Subject: Re: Thread safety issues

Re: Thread safety issues

From: Simon Josefsson <>
Date: Tue, 31 Aug 2010 09:53:50 +0200

jmk <> writes:

> On Mon, 2010-08-30 at 22:53 +0200, Daniel Stenberg wrote:
>> On Mon, 30 Aug 2010, jmk wrote:
>> > I've added a mutex lock around libssh2_session_init_ex(). This drastically
>> > cut down on it blowing up. However, it appears that some of the other
>> > functions may also have thread safety issues. Specifically, I had to also
>> > lock libssh2_userauth_keyboard_interactive() and libssh2_session_free().
>> > With all libssh2_* calls locked, I've been unable to get it to blow up.
>> > Certainly not ideal, but better than the alternative for now.
>> And are you using the mutex callbacks now for your crypto library of choice?
> I wasn't...
> I took a look at the threaded-ssl.c example from Curl and implemented
> their locking callbacks. With these callbacks and only a mutex for
> libssh2_session_init_ex(), everything appears stable now...

You shouldn't need any mutexes except the ones needed for the crypto
library. Maybe you could remove your own mutex and see if things
continue to work?

Of course, you still need to make sure you don't access one session from
more than one thread, but normally this is handled by having one thread
per session.

Received on 2010-08-31