authorgravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-09-23 11:41:31+02:00
committergravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-09-23 11:41:31+02:00
log0eed7ec9d51fe8c0dd22b72da0130ad9d31877d0
treeedabf258c98ede7cb8d06cfae73e3e9142ac0a48
parent58ee5f4e61cd9b7a9ba65798e2214efa3753a733

Eventloop: Fix deadlock in linux event loop implementation

A simple empty main with evented-io would not quit, because some threads were still waiting to be resumed (by the os). The os.write to the eventfd only wakes up one thread and thus there are multiple writes needed to wake up all the other threads.

1 files changed, 8 insertions(+), 3 deletions(-)

lib/std/event/loop.zig+8-3
......@@ -687,9 +687,14 @@ pub const Loop = struct {
687687
688688 switch (builtin.os.tag) {
689689 .linux => {
690 // writing 8 bytes to an eventfd cannot fail
691 const amt = os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
692 assert(amt == wakeup_bytes.len);
690 // writing to the eventfd will only wake up one thread, thus multiple writes
691 // are needed to wakeup all the threads
692 var i: usize = 0;
693 while (i < self.extra_threads.len + 1) : (i += 1) {
694 // writing 8 bytes to an eventfd cannot fail
695 const amt = os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
696 assert(amt == wakeup_bytes.len);
697 }
693698 return;
694699 },
695700 .macosx, .freebsd, .netbsd, .dragonfly => {