Are push and pop operations for arrays atomic?
Can i safely run
i = array.pop
...
array.push(i)
in GIL-threaded env?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.