views:

24

answers:

1

Are push and pop operations for arrays atomic? Can i safely run

i = array.pop
...
array.push(i)

in GIL-threaded env?

A: 

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.

rogerdpack