XaoS
XaoS copied to clipboard
Deadlock in multithreaded boundary trace
XaoS frequently hangs when multithreading is enabled. The issue appears to be in the boundary trace code. This is most likely due to some bug in the synchronization code for multithreading. It happens sometimes when the window is resized or some fractal parameter is changed that triggers a full recalculation of the image. It is probably a race condition since it is not consistently reproducible.
Several threads are blocked on a call to pthread_mutex_lock, which is called via the xth_lock macro.
The main thread is blocked here: https://github.com/xaos-project/XaoS/blob/master/src/engine/btraced.h#L353.
Other threads were executing one of these calls to addstack:
- https://github.com/xaos-project/XaoS/blob/master/src/engine/btraced.h#L282
- https://github.com/xaos-project/XaoS/blob/master/src/engine/btraced.h#L306
addstack is a multi-line macro defined here, whose first line is a call to xth_lock:
https://github.com/xaos-project/XaoS/blob/master/src/engine/btrace.cpp#L179
For now, I have just disabled multi threaded boundary tracing so it won't deadlock. Zooming will still use multiple threads if enabled because boundary trace is only used when initially calculating the fractal, and it's OK for that to be slower.