[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] releasing the GIL in the python extension

From: Tamas Nepusz
Subject: Re: [igraph] releasing the GIL in the python extension
Date: Sun, 20 Sep 2009 15:18:48 +0100

Tamas, in the python extension, why do you not release the GIL when performing calculations on graphs? Was there a specific reason not to do so?
Yes, there was. The igraph C core is not thread-safe:


In a nutshell: whenever igraph allocates memory for some purpose, it pushes the address of the allocated memory block to a global stack along with a destructor function that should be called should an error occur. If the calculation that required the memory block runs to completion without errors, it cleans up the allocated memory itself and then unrolls the stack. If an error happens, the calculation calls an error handler routine which unrolls the stack (calling the destructors associated to the memory addresses). Since there is only a single global stack, igraph functions that are run in parallel in different threads might end up freeing each other's memory should an error occur in one of them. Therefore there's no use in running multiple igraph functions in separate threads at the same time. That's why I keep the GIL locked -- even if you create multiple threads in Python and start calling igraph functions from them, the GIL will ensure that igraph's internal stack remains in a valid state.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]