[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#36609: 27.0.50; Possible race-condition in threading implementation
From: |
Eli Zaretskii |
Subject: |
bug#36609: 27.0.50; Possible race-condition in threading implementation |
Date: |
Sun, 06 Jun 2021 19:35:31 +0300 |
> From: dick.r.chiang@gmail.com
> Cc: Pip Cet <pipcet@gmail.com>, larsi@gnus.org, 36609@debbugs.gnu.org,
> Eli Zaretskii <eliz@gnu.org>
> Date: Sun, 06 Jun 2021 11:25:01 -0400
>
> #1. Want to revert commit 9c62ffb
This will bring back bug#36609, so we cannot do that without
discussing first why you think that commit was wrong.
> #2. Fails on tip of master, succeeds after patch in #1.
Please explain what does "fails" mean, and why do you think the above
commit is the culprit. (A much simpler test case will be
appreciated, btw.)
> Fails not necessarily because xgselect.c is wrong, but rather because
> channel-recv blocks on a mutex before channel-send can get its act
> together.
You mean, in this code:
(let ((channel (make-channel 1)))
(make-thread
(lambda nil
(channel-send (car channel) 42))
"produce")
(channel-recv (cdr channel))
(ignore-errors (enable-command 'list-threads))
(call-interactively #'list-threads))
? Here, channel-send is called by a new thread, created by
make-thread. In this code, it is _expected_ that channel-recv will be
called (by the main thread) _before_ channel-send is called by the new
thread, because make-thread creates a thread, but the newly created
thread doesn't run until it can acquire the global lock. Meanwhile,
the main thread continues running and calls channel-recv. The new
thread will not begin running, AFAIU, until the main thread calls
condition-wait inside channel-recv.
By "blocks on a mutex", did you mean that channel-recv blocks trying
to acquire the mutex here:
(cl-defgeneric channel-recv ((sink channel-terminal))
(with-mutex (oref sink mutex) <<<<<<<<<<<<<<<<<<<<<<<<<<
(with-slots (condition msg-queue) sink
If so, which thread holds that mutex at this point?
> #4. What #3 probably intended, succeeds after patch in #1.
Yes, race conditions can be solved by using sleep-for, but that's not
really a clean solution, at least not in my book.
- bug#36609: 27.0.50; Possible race-condition in threading implementation, dick . r . chiang, 2021/06/06
- bug#36609: 27.0.50; Possible race-condition in threading implementation,
Eli Zaretskii <=
- bug#36609: 27.0.50; Possible race-condition in threading implementation, dick . r . chiang, 2021/06/06
- bug#36609: 27.0.50; Possible race-condition in threading implementation, Eli Zaretskii, 2021/06/06
- bug#36609: 27.0.50; Possible race-condition in threading implementation, dick . r . chiang, 2021/06/09
- bug#36609: 27.0.50; Possible race-condition in threading implementation, Eli Zaretskii, 2021/06/10
- bug#36609: 27.0.50; Possible race-condition in threading implementation, dick . r . chiang, 2021/06/10
- bug#36609: 27.0.50; Possible race-condition in threading implementation, Eli Zaretskii, 2021/06/10
- bug#36609: 27.0.50; Possible race-condition in threading implementation, dick . r . chiang, 2021/06/10
- bug#36609: 27.0.50; Possible race-condition in threading implementation, Eli Zaretskii, 2021/06/10
- bug#36609: 27.0.50; Possible race-condition in threading implementation, dick . r . chiang, 2021/06/10
- bug#36609: 27.0.50; Possible race-condition in threading implementation, Eli Zaretskii, 2021/06/11