Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09db7fd

Browse files
committed
Expand OpenSSL and libssh2 thread safety documentation
1 parent 9f4e7c8 commit 09db7fd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

THREADING.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,19 @@ which locking function it should use. This means that libgit2 cannot
7272
know what to set as the user of libgit2 may use OpenSSL independently
7373
and the locking settings must survive libgit2 shutting down.
7474

75+
Even if libgit2 doesn't use OpenSSL directly, OpenSSL can still be used
76+
by libssh2 depending on the configuration. If OpenSSL is used both by
77+
libgit2 and libssh2, you only need to set up threading for OpenSSL once.
78+
7579
libgit2 does provide a last-resort convenience function
7680
`git_openssl_set_locking()` (available in `sys/openssl.h`) to use the
7781
platform-native mutex mechanisms to perform the locking, which you may
7882
rely on if you do not want to use OpenSSL outside of libgit2, or you
7983
know that libgit2 will outlive the rest of the operations. It is not
8084
safe to use OpenSSL multi-threaded after libgit2's shutdown function
81-
has been called.
85+
has been called. Note `git_openssl_set_locking()` only works if
86+
libgit2 uses OpenSSL directly - if OpenSSL is only used as a dependency
87+
of libssh2 as described above, `git_openssl_set_locking()` is a no-op.
8288

8389
If your programming language offers a package/bindings for OpenSSL,
8490
you should very strongly prefer to use that in order to set up
@@ -87,14 +93,14 @@ when using this function.
8793

8894
See the
8995
[OpenSSL documentation](https://www.openssl.org/docs/crypto/threads.html)
90-
on threading for more details.
96+
on threading for more details, and http://trac.libssh2.org/wiki/MultiThreading
97+
for a specific example of providing the threading callbacks.
9198

9299
Be also aware that libgit2 does not always link against OpenSSL
93100
if there are alternatives provided by the system.
94101

95-
libssh2 may be linked against OpenSSL or libgcrypt. If it uses
96-
OpenSSL, you only need to set up threading for OpenSSL once and the
97-
above paragraphs are enough. If it uses libgcrypt, then you need to
102+
libssh2 may be linked against OpenSSL or libgcrypt. If it uses OpenSSL,
103+
see the above paragraphs. If it uses libgcrypt, then you need to
98104
set up its locking before using it multi-threaded. libgit2 has no
99105
direct connection to libgcrypt and thus has not convenience functions for
100106
it (but libgcrypt has macros). Read libgcrypt's

0 commit comments

Comments
 (0)