Closed edwinyzh closed 3 years ago
Check all the update 1..4 I added above in the OP, here are my conclusions:
-D_REENTRANT
flagI think you could have different sessions running in different threads. Have not tested it.
I'm doing it now (have different ssh sessions in different threads), but will need more tests to confirm the stability.
On the other hand, to improve the thread-safety of libssh2, it'd suggest to add the -D_REENTRANT
flag when compiling the libssh2 DLL, although I'm not in a good position to create a PR for this since I'm not familiar with building c projects. :)
-D_REENTRANT
flag
This flag is for GCC only. I am linking with the thread-safe version of the std. library of Visual Studio anyway.
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
If I remember well it is only channels that cannot be used by a different threads simultaneously. Using different channels of the same session could also be thread safe.
Hello,
Is it safe to create multiple
ISshExec
out of the same session, and then use thoseISshExec
instances in multiple threads? Or do I have to use standalone session for each thread?Upate 1: After looking at TSshExec.Exec, the code access
FSession
without any locking mechanism, so I assume it's not thread-safe...Update 2: After looking at /CLibs/BuildWin32Lib.cmd, it seems that the dlls were not compiled with the
-D_REENTRANT
flag, so I assume adding that flag will improve the thread-safety as well.Update 3: The following two quotes from a thread in the libssh2 mail list are worth noting:
Update 4: Another useful quote: