thread-safety of FiberExecutor API functions
I'm wondering about correct and deterministic ways of interacting between the FiberExecutor and external threads.
Take this example:
using namespace lely;
io::IoGuard io_guard;
io::Context ctx;
io::Poll poll(ctx);
ev::Loop loop(poll.get_poll());
auto exec = loop.get_executor();
io::Timer timer(poll, exec, CLOCK_MONOTONIC);
io::CanController ctrl("can0");
io::CanChannel chan(poll, exec);
chan.open(ctrl);
canopen::AsyncMaster master(timer, chan, "/tmp/master.dcf", "");
master.Reset();
int counter = 0;
std::thread background([&](){
while (1) {
exec.post([&](){
fmt::print("task #{}\n", counter);
counter += 1;
});
usleep(100);
}
});
loop.run();
When testing, it runs without problems indefinitely. Stepping through the code with GDB, I can see that some Mutex locking happens inside the post() function, but the API documentation does not mention anything related to thread safety.
I think the documentation should explicitly mention which API functions are safe to call from different threads.
I'm particularly interested in posting to the executor, locking fiber mutexes and notifying fiber condition variables.
Thanks!
Edited by Michael Enßlin