chore(util/interrupt): improve comment

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-11-25 17:23:36 -08:00
parent 4eb62fef91
commit e29a2f4d11

View file

@ -44,18 +44,19 @@ void sleep_for(unsigned ms, unsigned step_ms = g_small_sleep);
class interruptible_thread {
std::atomic<std::atomic_bool*> m_flag_addr;
/*
The following auxiliary field is used to workaround
a nasty bug that occurs in some platforms.
On cygwin, it seems that the thread local storage is
deleted before the object m_thread is destructed.
The following auxiliary field is used to workaround a nasty bug
that occurs in some platforms. On cygwin, it seems that the
thread local storage is deleted before m_thread is destructed.
Then, the main thread may corrupt memory if it invokes
request_interrupt after the child thread referenced
by m_thread has terminated.
The method request_interrupt access the child thread
local storage pointed by m_flag_addr.
To avoid this bug, we use the a simple hack,
we reset m_flag_addr to m_dummy_addr before terminating
the execution of the main thread.
request_interrupt after the child thread referenced by m_thread
has terminated.
The method request_interrupt access the child
thread local storage pointed by m_flag_addr.
To avoid this bug, we use a simple hack, we reset m_flag_addr to
m_dummy_addr before terminating the execution of the child
thread.
*/
std::atomic_bool m_dummy_addr;
std::thread m_thread;