dougbinks / enkiTS

A permissively licensed C and C++ Task Scheduler for creating parallel programs. Requires C++11 support.
zlib License
1.66k stars 138 forks source link

Deadlock with WaitForNewPinnedTasks and WaitforAllAndShutdown #128

Closed spnda closed 1 month ago

spnda commented 1 month ago

Running the WaitForNewPinnedTasks example deadlocks within TaskScheduler::WaitforAll at the end when calling WaitforAllAndShutdown, since the pinned task thread will continue to run, as g_TS.GetIsRunning won't return false. The pinned task thread will then just continue to loop its function and the WaitforAll will never return, since that thread will report that it's doing something.

dougbinks commented 1 month ago

Thanks for the report - I'll take a look shortly.

spnda commented 1 month ago

I just noticed that the GetIsRunning function is deprecated and that GetIsShutdownRequested should be used instead. The example should be updated and the documentation should be changed to clarify that the other function should not be used. Also, perhaps it should be marked [[deprecated]] to clarify that it is deprecated since I didn't notice until reading the documentation by accident.

Perhaps I can send a PR?

dougbinks commented 1 month ago

I think the best option might be to make GetIsRunning() return GetIsShutdownRequested(), however this is used internally so another private function instead of GetIsRunning(). The C API also needs to be updated.

I also mark as deprecated and change the sample to use GetIsShutdownRequested().

Since deprecated is C++14 and enkiTS is C++11 that requires a macro to only enable if the feature is present.

Since this requires a few internal changes I think I would prefer to handle most of it, but if you would like to submit a PR for switching the sample to GetIsShutdownRequested() and optionally the [[deprecated]] using an ENKI_DEPRECATED macro then I would accept those, but I'm also happy to do them myself.

spnda commented 1 month ago

I have those changes locally already so I'll just push and open, thank you.