cpptime
cpptime copied to clipboard
mutithread erro coredump
qestion1 :
thread1 add a period timer and save time_id. thread2 is the timer thread.
afer thread2 unlock . thread 1 use the time_id to call Timer::remove() , in Timer::remove , delete the time_id and set handler to nullptr, but thread 1 is executing the handler. the coredump happen.
lock.unlock();
events[te.ref].handler(te.ref);
lock.lock();
what should i do to avoid the problem?
question 2: thread1 add a period timer and save time_id. thread2 is the timer thread.
thread 1 will call Timer::remove() in handler callback. while the handler is executing ,it call Timer::remove, But in Timer::remove set handler to nullptr . and so the program core dump.
events[id].valid = false;
events[id].handler = nullptr;
One way is to execute remove tid in the handler.