[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby interpreter thread safety

Thomas Sondergaard

9/4/2003 10:37:00 AM

I have a scenario where a ruby extension module starts real/os/heavy-weight
threads that may call back to ruby. As far as I understand the ruby
interpreter itself is not thread safe. How can I handle this thread-safety
problem?

Cheers,

Thomas


4 Answers

nobu.nokada

9/4/2003 11:09:00 AM

0

Hi,

At Thu, 4 Sep 2003 19:45:24 +0900,
Thomas Sondergaard wrote:
> I have a scenario where a ruby extension module starts real/os/heavy-weight
> threads that may call back to ruby. As far as I understand the ruby
> interpreter itself is not thread safe. How can I handle this thread-safety
> problem?

Run the ruby interpreter in a particular os-thread, and use
system provided queue.

--
Nobu Nakada

Jim Weirich

9/4/2003 11:10:00 AM

0

On Thu, 2003-09-04 at 06:45, Thomas Sondergaard wrote:
> I have a scenario where a ruby extension module starts real/os/heavy-weight
> threads that may call back to ruby. As far as I understand the ruby
> interpreter itself is not thread safe. How can I handle this thread-safety
> problem?

The general solution for any threaded code making calls to a non-thread
safe library is to do one of the following:

(a) Make calls into the library (callbacks in your case) from
only a single thread.
or (b) Serialize calls to the library by using a mutex of some type.

--
-- Jim Weirich jweirich@one.net http://onest...
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

Thomas Sondergaard

9/4/2003 11:41:00 AM

0

> The general solution for any threaded code making calls to a non-thread
> safe library is to do one of the following:
>
> (a) Make calls into the library (callbacks in your case) from
> only a single thread.
> or (b) Serialize calls to the library by using a mutex of some type.

Got it!

Thomas


Thomas Sondergaard

9/4/2003 11:47:00 AM

0


> Run the ruby interpreter in a particular os-thread, and use
> system provided queue.

Could you give me an example of such a system provided queue?

Cheers,

Thomas