ruby-changes:45129
From: nobu <ko1@a...>
Date: Tue, 27 Dec 2016 16:10:16 +0900 (JST)
Subject: [ruby-changes:45129] nobu:r57202 (trunk): thread.c: fix race between read and close
nobu 2016-12-27 16:10:11 +0900 (Tue, 27 Dec 2016) New Revision: 57202 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57202 Log: 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] Modified files: trunk/thread.c Index: thread.c =================================================================== --- thread.c (revision 57201) +++ thread.c (revision 57202) @@ -2164,14 +2164,22 @@ rb_thread_fd_close(int fd) https://github.com/ruby/ruby/blob/trunk/thread.c#L2164 { rb_vm_t *vm = GET_THREAD()->vm; rb_thread_t *th = 0; + int busy; + retry: + busy = 0; list_for_each(&vm->living_threads, th, vmlt_node) { if (th->waiting_fd == fd) { VALUE err = th->vm->special_exceptions[ruby_error_closed_stream]; rb_threadptr_pending_interrupt_enque(th, err); rb_threadptr_interrupt(th); + busy = 1; } } + if (busy) { + rb_thread_schedule_limits(0); + goto retry; + } } /* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/