|
From: | Tamas Nepusz |
Subject: | Re: [igraph] releasing the GIL in the python extension |
Date: | Sun, 20 Sep 2009 16:37:08 +0100 |
So, would the following scenario result in memory corruption if the GIL was released?:Nope. The data structures created _during_ the calculation would possibly be freed in thread 2 (not the copy of the graph itself). So, for instance, let us assume that you are calculating betweenness centrality. Betweenness centrality requires a few temporary vectors to store partial result. What happens is:in python, create graph, make a full copy of the graph (not a weakref), in thread 1, with first graph, calculate something in thread 2 with the copy of the graph, calculate something thread 1 calculation fails, error function/destructor is called, ... thread 2's graph (the copy) gets freed?
1. In thread 1, the calculation starts with the first graph2. Thread 1 allocates the temporary vectors and pushes the memory addresses down the stack
3. In thread 2, the calculation starts with the second graph4. Thread 2 allocates the temporary vectors and pushes the memory addresses down the stack
5. Thread 1 finishes the calculation. Since thread 1 knows that it pushed, say, two addresses down the stack (for the temporary vectors -- this is just an example, so the numbers may be arbitrary), it pops the topmost two memory addresses from the stack. These addresses happen to belong to thread 2 since those were pushed later, so thread 1 could happily free the memory address that is being used by thread 2.
-- Tamas
[Prev in Thread] | Current Thread | [Next in Thread] |