XaoS icon indicating copy to clipboard operation
XaoS copied to clipboard

Deadlock in multithreaded boundary trace

Open jblang opened this issue 4 years ago • 1 comments

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

jblang avatar Jan 05 '20 17:01 jblang

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.

jblang avatar Jan 06 '20 00:01 jblang