SpartanJ / efsw

efsw is a C++ cross-platform file system watcher and notifier.
Other
662 stars 101 forks source link

reslove file watcher inotfiy destructor deadlock #151

Closed ashione closed 1 year ago

ashione commented 1 year ago

There is deadlock between main thread executing destructor and hand action thread. So this PR try create a new bool member property to mark hand action thread working or not. Besides, file watcher destructor will wait until action thread finished, which gurantees backgroud thread could be terminated successfully.

SpartanJ commented 1 year ago

Thanks for your contribution! I'm still trying to visualize the deadlock in my head. I don't completely understand how this gets locked but well I guess it makes some sense.

ashione commented 1 year ago

Thanks for your contribution! I'm still trying to visualize the deadlock in my head. I don't completely understand how this gets locked but well I guess it makes some sense.

The key reason is that destructor holds init_lock mutex so that mThread can not join and wait the worker-thread finish.

SpartanJ commented 1 year ago

Oh, you're right, thanks for the clarification.