Subject: Re: Thread safety issues

Re: Thread safety issues

From: Simon Josefsson <>
Date: Tue, 31 Aug 2010 21:54:58 +0200

jmk <> writes:

> On Tue, 2010-08-31 at 09:53 +0200, Simon Josefsson wrote:
>> 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?
> It's certainly possible I've messed stuff up, but without the mutex for
> libssh2_session_init_ex(), things still occasionally blow up. With a
> mutex for that one call and the crypto callback functions, things *seem*
> completely stable.

Do you call libssh2_init? The libssh2_session_init_ex function
initializes the library when needed, maybe you cause two threads to
initialize the library at the same time. By doing an explicit
libssh2_init at the start of your program, that should be avoided.

It may also be that I've missed something, and libssh2_session_init_ex
is intended to be thread-unsafe too. But then we have a documentation
problem, since this is not stated in the function man page.

Received on 2010-08-31