Hello all,

I've been writing ruby bindings to a commercial messaging software
product we use at work (with which I am very familiar) and we have had
wonderful success!  Extending Ruby with native code is truly enjoyable;
however, in attempting to create a more sophisticated integration, I've
run into an issue that has lead me down confusing paths.  Perhaps people
here can advise.

In this library, messages can be sent to other components that use the
same library asynchronously; when a message is submitted, the caller
also provides a callback handler as a pointer to an object that
implements a particular interface.  I would like the Ruby interface user
to provide a Proc that gets wrapped and called by the native callback
handler implementation when the callback handler is invoked by the
library.  Of concern is that the pthreads that invoke the callback
handler could be different than (or could be the same as) the thread
that called submit; however, they are guaranteed to invoke the callback
method (and therefore the callback Proc provided by the user) in a
synchronized fashion, even though they may be in different pthreads
(they are abstracted by a pool).  The current implementation works under
very light load (perhaps when the submitter and callback threads are the
same?) but crashes more often than not with Segmentation Faults,
notifications of cross-thread scheduling, and such.

My attempt to make this library's threading implementation play nicely
with Ruby's has been simplistic; can someone provide a general strategy
for encouraging Ruby's threads and scheduling system to fit within an
external library's model?  I've spent some time reading information on
the mailing lists, other extension modules' source code, as well as
Ruby's own so any advice is welcome.

Cheers,
-mike

Michael Ericson



***********************************************************************
Bear Stearns is not responsible for any recommendation, solicitation, 
offer or agreement or any information about any transaction, customer 
account or account activity contained in this communication.
***********************************************************************