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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With