6

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?

Ether
  • 53,118
  • 13
  • 86
  • 159
Mike
  • 23,892
  • 18
  • 70
  • 90

1 Answers1

2

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
  • 151,642
  • 46
  • 269
  • 291