Besides sharing variables between threads, the documentation also explains how to lock shared variables to avoid clashes when multiple threads try to access a variable at the same time.
Comment on Re: Updating global variable in multi-threaded program