Subject: Re: Thread safety issues

Re: Thread safety issues

From: Michel Valin <>
Date: Tue, 31 Aug 2010 13:19:27 -0400

Daniel Stenberg wrote:
> On Tue, 31 Aug 2010, Michel Valin wrote:
>>> 1) Provide an APIs and let the caller set mutex hooks.
>>> Pros:
>>> - The library does not have to link a thread library.
>>> - No layering violation.
>>> Cons:
>>> - It is easy to forget to make this call when you are writing
>>> a multi-threaded program, which can lead to subtle errors.
>> This one can be alleviated by having the library issue a warning
>> message at first initialization (lib_sh2_init) reminding the user that
>> the thread-safe hook is not set.
> Not really.
> First, how would that warning be issued? We can't assume that the
> library can send any output anywhere that anyone will notice.

true, one can never be sure that stderr will be connected
(or that it will be read if it is :-) )

> Secondly, the library doesn't know if it will be used threaded so it
> would have no warn on every init that doesn't use the mutex callbacks
> even if they wouldn't be needed!

true again, that's why i said alleviated rather than solved. call that
collateral noise. in that case a non threaded program would have to
supply a do nothing mutex hook. (definitely not a pro)


Michel Valin
Received on 2010-08-31