Bosma / Scheduler

Modern C++ Scheduling Library
MIT License
272 stars 74 forks source link

Crash on manage_task while program end and Scheduler destructor called #2

Closed cloud9370 closed 6 years ago

cloud9370 commented 6 years ago

I just tried your example.cpp and modified the sleep time from 10 minutes to 10 seconds in main thread. That made my program crash on manage_task method while program ended.

I use std::cerr to show the execute order, then I found that destructor called and manage_task called after destructor. That made program crashed.

I'm using VS2017 to build program. Please check this problem. Thanks.

cloud9370 commented 6 years ago

I found that thread_pool destructor was executed after Scheduler destructor. That makes the thread_pool.stop(true) execute after Scheduler desctructor.

Bosma commented 6 years ago

Thanks for the report. I pushed a fix. Previously, the tasks variable was destructed before the thread pool. The manager thread could attempt to access tasks while looping for the final time, but tasks would be destroyed already. Just switched their ordering.