ruby atomic operations in multithreaded environment
开发者_如何学PythonAre push and pop operations for arrays atomic? Can i safely run
i = array.pop
...
array.push(i)
in GIL-threaded env?
You can look in the c code (array.c) if it calls any ruby method calls (rb_funcall) then it's not thread safe, I believe. Otherwise it should be...
You could easily override #pop et al and make them have their own synchronization.
精彩评论