evloop: Fix workqueue threading race conditions and eliminate crash-prone synchronization patterns
This MR fixes multiple threading issues in the workqueue system that could cause crashes under certain conditions, while eliminating poor synchronization practices that violate threading principles.
Critical issues fixed:
- Race condition in global control_lock_owner variable - multiple threads could simultaneously check/modify this value leading to undefined behavior
- Potential infinite loop with tor_sleep_msec(10) polling - if worker threads hang, main thread loops forever
- Cross-thread mutex ownership transfer violating POSIX - undefined behavior that could cause deadlocks or crashes on some platforms
Improvements:
• Replaced global lock ownership tracking with proper condition variable synchronization • Eliminated polling loop with robust condition variable wait and timeout handling • Each thread now manages its own lock lifecycle following POSIX threading principles • Added comprehensive documentation and error handling for edge cases
Impact: Prevents potential crashes and hangs while improving code maintainability. No performance impact on normal operation.
Type: Critical Bug Fix / Code Quality Improvement