Skip to content

Commit b401273

Browse files
committed
Merge branch 'threading-docs'
2 parents 6872928 + 02ab484 commit b401273

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

docs/threading.md

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
Threads in libgit2
1+
Threading in libgit2
22
==================
33

4-
You may safely use any libgit2 object from any thread, though there
5-
may be issues depending on the cryptographic libraries libgit2 or its
4+
Unless otherwise specified, libgit2 objects cannot be safely accessed by
5+
multiple threads simultaneously.
6+
7+
There are also caveats on the cryptographic libraries libgit2 or its
68
dependencies link to (more on this later). For libgit2 itself,
79
provided you take the following into consideration you won't run into
810
issues:
@@ -26,11 +28,11 @@ The error message is thread-local. The `git_error_last()` call must
2628
happen on the same thread as the error in order to get the
2729
message. Often this will be the case regardless, but if you use
2830
something like the [GCD](http://en.wikipedia.org/wiki/Grand_Central_Dispatch)
29-
on Mac OS X (where code is executed on an arbitrary thread), the code
31+
on macOS (where code is executed on an arbitrary thread), the code
3032
must make sure to retrieve the error code on the thread where the error
3133
happened.
3234

33-
Threads and cryptographic libraries
35+
Threading and cryptographic libraries
3436
=======================================
3537

3638
On Windows
@@ -44,52 +46,42 @@ steps necessary. If you are using a MinGW or similar environment where
4446
libssh2 uses OpenSSL or libgcrypt, then the general case affects
4547
you.
4648

47-
On Mac OS X
49+
On macOS
4850
-----------
4951

50-
By default we use libcurl to perform the encryption. The
51-
system-provided libcurl uses SecureTransport, so no special steps are
52-
necessary. If you link against another libcurl (e.g. from homebrew)
53-
refer to the general case.
54-
55-
If the option to use libcurl was deactivated, the library makes use of
56-
CommonCrypto and SecureTransport for cryptographic support. These are
57-
thread-safe and you do not need to do anything special.
52+
By default we make use of CommonCrypto and SecureTransport for cryptographic
53+
support. These are thread-safe and you do not need to do anything special.
5854

5955
Note that libssh2 may still use OpenSSL itself. In that case, the
6056
general case still affects you if you use ssh.
6157

6258
General Case
6359
------------
6460

65-
If it's available, by default we use libcurl to provide HTTP tunneling support,
66-
which may be linked against a number of cryptographic libraries and has its
67-
own
68-
[recommendations for thread safety](https://curl.haxx.se/libcurl/c/threadsafe.html).
69-
70-
If there are no alternative TLS implementations (currently only
71-
SecureTransport), libgit2 uses OpenSSL in order to use HTTPS as a transport.
72-
OpenSSL is thread-safe starting at version 1.1.0. If your copy of libgit2 is
73-
linked against that version, you do not need to take any further steps.
61+
libgit2 will default to OpenSSL for HTTPS transport (except on Windows and
62+
macOS, as mentioned above). On any system, mbedTLS _may_ be optionally
63+
enabled as the security provider. OpenSSL is thread-safe starting at
64+
version 1.1.0. If your copy of libgit2 is linked against that version,
65+
you do not need to take any further steps.
7466

7567
Older versions of OpenSSL are made to be thread-implementation agnostic, and the
7668
users of the library must set which locking function it should use. libgit2
7769
cannot know what to set as the user of libgit2 may also be using OpenSSL independently and
7870
the locking settings must then live outside the lifetime of libgit2.
7971

8072
Even if libgit2 doesn't use OpenSSL directly, OpenSSL can still be used by
81-
libssh2 or libcurl depending on the configuration. If OpenSSL is used by
73+
libssh2 depending on the configuration. If OpenSSL is used by
8274
more than one library, you only need to set up threading for OpenSSL once.
8375

84-
If libgit2 is linked against OpenSSL, it provides a last-resort convenience function
76+
If libgit2 is linked against OpenSSL < 1.1.0, it provides a last-resort convenience function
8577
`git_openssl_set_locking()` (available in `sys/openssl.h`) to use the
8678
platform-native mutex mechanisms to perform the locking, which you can use
8779
if you do not want to use OpenSSL outside of libgit2, or you
8880
know that libgit2 will outlive the rest of the operations. It is then not
8981
safe to use OpenSSL multi-threaded after libgit2's shutdown function
9082
has been called. Note `git_openssl_set_locking()` only works if
9183
libgit2 uses OpenSSL directly - if OpenSSL is only used as a dependency
92-
of libssh2 or libcurl as described above, `git_openssl_set_locking()` is a no-op.
84+
of libssh2 as described above, `git_openssl_set_locking()` is a no-op.
9385

9486
If your programming language offers a package/bindings for OpenSSL,
9587
you should very strongly prefer to use that in order to set up

0 commit comments

Comments
 (0)