thread.c (sleep_*): check interrupt before changing th->status

Having threads switch before we sleep can cause applications
to misread the state of the thread.  Now, we are consistent
with blocking_region_begin behavior and change th->status
AFTER checking interrupts.

Maybe this can fix [Bug #15002]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2018-08-18 18:29:28 +00:00
Родитель c742050ea5
Коммит 9e59487a38
1 изменённых файлов: 2 добавлений и 2 удалений

Просмотреть файл

@ -1186,8 +1186,8 @@ sleep_forever(rb_thread_t *th, unsigned int fl)
int woke;
status = fl & SLEEP_DEADLOCKABLE ? THREAD_STOPPED_FOREVER : THREAD_STOPPED;
th->status = status;
RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
th->status = status;
while (th->status == status) {
if (fl & SLEEP_DEADLOCKABLE) {
th->vm->sleeper++;
@ -1292,8 +1292,8 @@ sleep_timespec(rb_thread_t *th, struct timespec ts, unsigned int fl)
getclockofday(&end);
timespec_add(&end, &ts);
th->status = THREAD_STOPPED;
RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
th->status = THREAD_STOPPED;
while (th->status == THREAD_STOPPED) {
native_sleep(th, &ts);
woke = vm_check_ints_blocking(th->ec);