alytantawyy commented on PR #55464: URL: https://github.com/apache/arrow/pull/55464#issuecomment-6909250473
> OK. Could you explain the following? > > 1. Why don't we need a mutex for `garrow_file_system_get_extension_point()`? > 2. Why do we need `GRecMutex` instead of `GMutex` for `garrow_file_system_register_type()`? > 3. Is this still thread-safe with "registration directly through GIO"? Thanks for your questions @kou , I looked into GIO's implementation and here's what I found: 1- `garrow_file_system_get_extension_point()` uses a function local static variable where its initialization is thread safe in C++11 and later - this ensures that the initialization lambda runs only once even when multiple threads call it concurrently. That's why a mutex isn't needed. 2- I used `GRecMutex` to account for potential reentrant registration during GIO's lazy module loading - `g_io_extension_point_get_extension_by_name()` can trigger lazy module loading which may execute initialization code that calls `garrow_file_system_register_type()` again on the same thread - `GMutex` would cause a deadlock in this situation whereas `GRecMutex` allows recursive locking. I chose `GRecMutex` defensively in case of a possible callback. 3- For direct registration through GIO, the current implementation cannot guarantee thread safety when another module calls` g_io_extension_point_implement() `directly while Arrow GLib is performing a lookup - from my inspection of GIO's source code, I saw that registration modifies the extension list and lookup traverses it without shared synchronization around those operations. One thing we could do here is clarify the intended registration contract: require external file system modules to register through `garrow_file_system_register_type()` where thread safety is guaranteed through the mutexes we implemented. Another approach here could be to require filesystem modules to complete registration during initialization before concurrent lookups begin - this could also be documented and clarified as the intended registration contract. Please let me know what you think the best approach is whenever you get the chance, thanks! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
