On Thu, 3 May 2001, Benjamin Sugars wrote:

> On Thu, 3 May 2001, Chris Stith wrote:
> 
> > Really, it does help to let the user know, but wouldn't it be
> > better to be able to declare an XS module to be thread safe in the
> > Perl program calling it or perhaps in the XS itself? This would
> > require YAFC (yet another function call), but it would be a way to
> > control whether or not perl will single-thread the calls.
> > 
> >     use Foo;
> >     threadsafe Foo;
> > 
> > It's ugly, but it would allow an easy way to let perl know whether
> > it can safely treat calls to an XS based module as reentrant.
> 
> Would not the module itself have a better idea about thread safety than
> the calling environment?
> 
> But I don't see how this helps.  Simply serializing calls into a
> non-thread-safe library doesn't make it thread-safe.  Or perhaps I'm
> misunderstanding your suggestion?

The documentation for a library should state whether or not it is
thread-safe. Serializing calls to a library certainly doesn't make
it thread-safe, but serializing calls to individual nonreentrant
functions within the library keeps them from puking all over your
program.

My suggestion is to let libraries that are threadsafe (system
libraries as well as Perl moduels would be nice) be used as such
so the advantages of that can be realized, while at the same time
defaulting to serialized calls for libraries which are not, so
your threaded programs which need to call nonreentrant functions
can do so with some level of safety.

Chris

-- 
Even in the worst of times, there is always someone who's
never had it better. Even in the best of times, there is
always someone who's never had it worse.

Reply via email to