开发者

ruby atomic operations in multithreaded environment

开发者 https://www.devze.com 2023-01-09 08:14 出处:网络
开发者_如何学PythonAre push and pop operations for arrays atomic? Can i safely run i = array.pop ...

开发者_如何学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.

0

精彩评论

暂无评论...
验证码 换一张
取 消