Skip to content

Conversation

ngoldbaum
Copy link
Contributor

@ngoldbaum ngoldbaum commented Aug 21, 2025

c.f. #187

Adds new docs describing the thread safety guarantees CFFI offers. Includes a worked example demonstrating how to use a thread-unsafe C library safely with a threading.Lock.

@ngoldbaum ngoldbaum mentioned this pull request Aug 21, 2025
3 tasks
Copy link
Contributor

@arigo arigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a global lock like this is necessary it is not safe for more than one thread to simultaneously call into any part of the library. Missing "if" or "when" in that sentence?

As of version 2.0, CFFI generates thread-safe bindings to C libraries. What's new in 2.0 is the GIL-free version of CFFI. CFFI has always generated thread-safe bindings with its GIL-using version, and now in 2.0 it continues to do so in its GIL-free version. I think that most of what you say in your (otherwise great and useful!) text applies equally to both versions.

@ngoldbaum
Copy link
Contributor Author

You’re right, what’s there right now isn’t correct. I’ll fix it tomorrow. Thanks for giving this a read.

@ngoldbaum
Copy link
Contributor Author

I’ll fix it tomorrow.

Fixed, I also took the opportunity to expand the text a little with some more advice.

Copy link

@clin1234 clin1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mattip
Copy link
Contributor

mattip commented Aug 25, 2025

LGTM, will merge in a day or two unless another reviewer has more comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants