diff options
| author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2021-07-28 19:55:55 +1200 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2021-09-26 20:49:54 +0900 |
| commit | 8ac058b64577d9b6fb1ee998d0fa7800529d7d34 (patch) | |
| tree | 840566542980745ab96d859b503671ea368062e1 /test/fiber/scheduler.rb | |
| parent | 7d4a0c4b93cbdf40a9a43c4974199405099a8545 (diff) | |
Fix potential hang when joining threads.
If the thread termination invokes user code after `th->status` becomes
`THREAD_KILLED`, and the user unblock function causes that `th->status` to
become something else (e.g. `THREAD_RUNNING`), threads waiting in
`thread_join_sleep` will hang forever. We move the unblock function call
to before the thread status is updated, and allow threads to join as soon
as `th->value` becomes defined.
This reverts commit 6505c77501f1924571b2fe620c5c7b31ede0cd22.
Diffstat (limited to 'test/fiber/scheduler.rb')
| -rw-r--r-- | test/fiber/scheduler.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/test/fiber/scheduler.rb b/test/fiber/scheduler.rb index 0553e386f5..df82c2ff93 100644 --- a/test/fiber/scheduler.rb +++ b/test/fiber/scheduler.rb @@ -100,8 +100,10 @@ class Scheduler self.run ensure - @urgent.each(&:close) - @urgent = nil + if @urgent + @urgent.each(&:close) + @urgent = nil + end @closed = true @@ -196,3 +198,13 @@ class BrokenUnblockScheduler < Scheduler raise "Broken unblock!" end end + +class SleepingUnblockScheduler < Scheduler + # This method is invoked when the thread is exiting. + def unblock(blocker, fiber) + super + + # This changes the current thread state to `THREAD_RUNNING` which causes `thread_join_sleep` to hang. + sleep(0.1) + end +end |
