Subject: Re: Libss2 in multithread environment

Re: Libss2 in multithread environment

From: Peter Stuge <>
Date: Wed, 21 Apr 2010 11:37:30 +0200

Babaladi, Prabhanand wrote:
> I am trying to use the libssh2 library in multithread environment,
> but it is not working in my case.

Basically multithreading is not supported in libssh2 at this time.

> 1. Creating session
> 2. In a multithread environment, each thread is sharing this
> session in synchronized manner and getting the channels.

Fine, but..

> 3. Using channel which got above step execute the command and read
> output.

..only one channel at a time can ever be used, and most importantly -
note that you must drain the SSH-protocol-level packet completely in
libssh2 before you can reliably allow another thread to use it's

If you are using non-blocking libssh2 calls this is difficult for
outgoing data, since you must track the progress of each data buffer
that you send out via libssh2.

Using blocking mode it may be easier, but I am not sure if it will
make a difference for you.

Give it a shot.

Received on 2010-04-21