Repository navigation
Would it be possible to make libvips fork safe? #3577
Replies: 3 comments 9 replies
|
Hi @casperisfine, My understanding is that fork and threads are fundamentally incompatible. Suppose you have a mutex (for example) that's being held by a thread, and then another thread forks. Now the child process has a copy of the mutex memory area (is locked, held by process 12345, etc.), but no thread 12345. Everything will break horribly. libvips tries to work around this by delaying threads for as long as possible -- the first thread is only created when the first pixel is processed. However, once you have processed some pixels, the threading system is built, and forking after that point is likely to end in disaster. Making I think what we really need is a test case that replicates the pattern of forking and threading that's failing in these cases. If we have that, maybe we can find some other way around this issue. It would ideally be small, complete and self-contained, but I realize that can be very hard to do :( (I hope I've not misunderstood the problem, please put me right if I have) |
|
So this should work:
But if you move the fork after 4., and esp. if it's after 5., everything will break. (again, that's my understanding, corrections very welcome) |
|
This is good reading: libvips/ruby-vips#155 I'd forgotten the details. It seems just adding vips to your gemfile on macos might fix this. |
Uh oh!
There was an error while loading. Please reload this page.
Somewhat related to #2077, but I'm making a new discussion for clarity.
Context
libvipsand its dependencies use threads internally, so when an application called intolibvipsand laterfork(2), all threads but the one that calledforkdie, and can potentially leave mutexes and such locked with no way to unlock them. In other words after afork(2), all bets are off.The issue is that in languages with a GIL like Ruby and Python, forking is a very common way to achieve parallelism, so
libvipslack of fork safety makes it challenging to use in these environments.Question
How hard would it be to make
libvipsfully fork safe? Are you open to contributions / sponsoring on that front?In #2077 you mentioned that
vips_shutdown()could be improved so users could callvips_init()again later?have you explored that idea further, was there any major blocker?
All reactions