1 From 5db4077e9f5166033637d2af9532ec6144b85646 Mon Sep 17 00:00:00 2001
2 From: Maxime Devos <maximedevos@telenet.be>
3 Date: Thu, 30 Jun 2022 14:21:47 +0000
4 Subject: [PATCH 1/2] Fix behaviour of 'epoll-wake!' after 'run-fibers'.
6 This avoids the "epoll instance is dead" error noticed in
7 GNUnet-Scheme's test suite, as reported at
8 <https://github.com/wingo/fibers/issues/61>.
9 A test is added in the next commit.
11 This patch has been applied upstream, but there hasn't been
12 a new release yet at time of writing.
14 * fibers/epoll.scm (epoll-wake!)[dead]: Instead of throwing an error,
17 fibers/epoll.scm | 8 +++++++-
18 1 file changed, 7 insertions(+), 1 deletion(-)
20 diff --git a/fibers/epoll.scm b/fibers/epoll.scm
21 index d26db4d..eb63242 100644
22 --- a/fibers/epoll.scm
23 +++ b/fibers/epoll.scm
27 ;;;; Copyright (C) 2016 Andy Wingo <wingo@pobox.com>
28 +;;;; Copyright (C) 2022 Maxime Devos <maximedevos@telenet.be>
30 ;;;; This library is free software; you can redistribute it and/or
31 ;;;; modify it under the terms of the GNU Lesser General Public
32 @@ -135,7 +136,12 @@ epoll wait (if appropriate)."
34 (primitive-epoll-wake (fileno (epoll-wake-write-pipe epoll))))
36 - ('dead (error "epoll instance is dead"))))
37 + ;; This can happen if a fiber was waiting on a condition and
38 + ;; run-fibers completes before the fiber completes and afterwards
39 + ;; the condition is signalled. In that case, we don't have to
40 + ;; resurrect the fiber or something, we can just do nothing.
41 + ;; (Bug report: https://github.com/wingo/fibers/issues/61)
44 (define (epoll-default-folder fd events seed)
45 (acons fd events seed))
47 From c01d3853eb56ea4adacc31f51f6e917f8c0abe1c Mon Sep 17 00:00:00 2001
48 From: Maxime Devos <maximedevos@telenet.be>
49 Date: Thu, 30 Jun 2022 14:18:36 +0000
50 Subject: [PATCH 2/2] Test for issue #61.
52 * tests/conditions.scm: Add a test.
54 tests/conditions.scm | 20 ++++++++++++++++++++
55 1 file changed, 20 insertions(+)
57 diff --git a/tests/conditions.scm b/tests/conditions.scm
58 index 505c42a..179605a 100644
59 --- a/tests/conditions.scm
60 +++ b/tests/conditions.scm
62 ;; Fibers: cooperative, event-driven user-space threads.
64 ;;;; Copyright (C) 2016 Free Software Foundation, Inc.
65 +;;;; Copyright (C) 2022 Maxime Devos <maximedevos@telenet.be>
67 ;;;; This library is free software; you can redistribute it and/or
68 ;;;; modify it under the terms of the GNU Lesser General Public
71 #:use-module (fibers conditions)
72 #:use-module (fibers operations)
73 + #:use-module (fibers scheduler)
74 #:use-module (fibers timers))
81 +;; Make a condition, wait for it inside a fiber, let the fiber abruptly
82 +;; terminate and signal the condition afterwards. This tests for the bug
83 +;; noticed at <https://github.com/wingo/fibers/issues/61>.
85 + (let ((cv (make-condition)))
88 + (spawn-fiber (lambda () (wait cv)))
89 + (yield-current-task)) ; let the other fiber wait forever
90 + ;; This test relies on not draining -- this is the default,
91 + ;; but let's make this explicit.
93 + ;; For simplicity, disable concurrency and preemption.
94 + ;; That way, we can use 'yield-current-task' instead of an
95 + ;; arbitrary sleep time.
96 + #:hz 0 #:parallelism 1)
97 + (signal-condition! cv)))
99 (exit (if failed? 1 0))