Am 02.01.2018 um 22:40 schrieb Benjamin Schaaf:
If I start a timer in a task on the main thread, say while handling a web request, I can't
rearmorstopthat timer from a worker task or manually spawned thread.This is due to a
debug assertinlibevent2driver:debug assert(m_ownerThread is () @trusted { return Thread.getThis(); } ());(eg. In
core/vibe/core/drivers/libevent2.d:483for version0.8.2)From limited testing, my code seems to have no issues in release mode (ie. seemingly the only thing breaking my code are these debug checks).
Are
rearmandstopnot thread safe? Is the debug statement actually saving me from race conditions/data races, or could they be removed?
Except for ManualEvent and the derived synchronization primitives, all
entities are thread-exclusive. Using them from other threads can
sometimes lead to the wrong state being set (due to the use of some
global TLS variables) and will definitely create race conditions in the
event driver.
For this case, the simplest solution is probably to simply start a task
in the main thread that loops over std.concurrency.receive, and then
send messages to that Task's Tid to trigger the rearm/stop actions.