Wasp's Nest: A Lock-Free Concurrency Pattern In Python
emptysquare.net
emptysquare.net
Decent writeup of read-copy-update, at least. I'm annoyed that he never provided any actual measurements to prove that the addition of a mutex is a bad solution for the problem, or too slow.
It's really, really easy to write a 'correct' lock-free implementation that gets dramatically outperformed by a simpler implementation using mutexes. It all depends on how you use the mutex, how fast your mutex implementation is, how fast your atomic primitives are, and other details like whether you're sharing cache pages.
<s>one reason you cannot think this way is because the GIL is a CPython concept. if you program with this restriction in mind, you're not writing python, you're writing python targeted to the CPython implementation of python.</s> - edit, this is actually wrong, a comment below explains why.
the other reason is because it is misunderstanding of how the GIL works. the GIL is acquired for each python instruction so no two instructions will race against each other in the interpreter. however, two threads could have any arbitrary ordering of instructions and there is not a strict correspondence of instructions to statements.
CPython uses native threads for python threads so if you make multiple threads, they will race against each other. please don't make any assumptions about how the interpreter and those threads will interact, and just use either locks with good judgement or a lock-free algorithm that is grounded in a very deep understanding of the languages memory model.
I'd strikethrough edit my post but I don't know how to make strikethrough markup :(
[1] http://www.justsoftwaresolutions.co.uk/threading/non_blockin...