How to write thread safe ruby code?

Hi,

I am using RUBY VERSION: 1.8.6,Rails 2.3.2 and Backgroundrb. I am
running into inconsistent data when using 10 threads per backgroundrb
worker class.Each thread retrieves orders for each of the store.

And at least in store i see the orders of the other store. This occurs
when run multiple threads at a time. I am running 10-20 threads for a
backgroundrb worker class at a time.So orders of the one thread are
copied into another thread. Not all the orders are copied i see only few
orders are copied.

Can any one help in this regard?

http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Thread
might help (especially “controlling concurrency”)