mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
thread.c: fix race between read and close
* thread.c (rb_thread_fd_close): wait until all threads using the fd finish the operation, not to free the buffer in use. [ruby-core:78845] [Bug #13076] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57202 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
20659e0036
commit
bc855ef139
1 changed files with 8 additions and 0 deletions
8
thread.c
8
thread.c
|
@ -2164,14 +2164,22 @@ rb_thread_fd_close(int fd)
|
||||||
{
|
{
|
||||||
rb_vm_t *vm = GET_THREAD()->vm;
|
rb_vm_t *vm = GET_THREAD()->vm;
|
||||||
rb_thread_t *th = 0;
|
rb_thread_t *th = 0;
|
||||||
|
int busy;
|
||||||
|
|
||||||
|
retry:
|
||||||
|
busy = 0;
|
||||||
list_for_each(&vm->living_threads, th, vmlt_node) {
|
list_for_each(&vm->living_threads, th, vmlt_node) {
|
||||||
if (th->waiting_fd == fd) {
|
if (th->waiting_fd == fd) {
|
||||||
VALUE err = th->vm->special_exceptions[ruby_error_closed_stream];
|
VALUE err = th->vm->special_exceptions[ruby_error_closed_stream];
|
||||||
rb_threadptr_pending_interrupt_enque(th, err);
|
rb_threadptr_pending_interrupt_enque(th, err);
|
||||||
rb_threadptr_interrupt(th);
|
rb_threadptr_interrupt(th);
|
||||||
|
busy = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (busy) {
|
||||||
|
rb_thread_schedule_limits(0);
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue