views:

76

answers:

1

I have the following Perl code:

push(@myArray, $myValue);

Is the operation atomic, or will I need to use locks, if multiple threads will be performing this same operation on many threads?

+2  A: 

The thread safety of most functions in perl depends on their underlying C routines, and in the case of built-ins, like push there is no mention of thread safety, so you must assume it is not.

Check out the perlthrtut man page, in particular the section titled "Basic Semaphores". Using a semaphore you can enforce mutual exclusion in arbitrary sections of code.

maerics