See pthreads tutorial .. protecting shared resources. It looks like you want to use a mutex on the shared variable, there is example code there, using a mutex lock, further down in the tutorial. Whether it will work under Perl threads, I don't know.
I need to use the lock in the Inline::C parts and the regular perl parts. If the implementation uses pthreads that's great, but I still need to identify the actual mutexes used by the interpreter.