(we observed that select(2) was canceled by errno=514 on
boron == Linux/Xen environment)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32325 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
machine stack for the timer thread at least 12KB. FreeBSD 8.2
AMD64 causes machine stack overflow (SIGSEGV) only with
PTHREAD_STACK_MIN (maybe defined as 2KB).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
communication pipe to avoid timing bug (process termination timing).
The communication pipe will closed by OS.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32276 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
In timer thread, signal handler shoul use it.
The patch is contributed by Eric Wong <normalperson@yhbt.net>.
Refs: [ruby-core:37644] and [ruby-core:37647]
* thread_pthread.c: use rb_async_bug_errno().
And replace all fprintf() to write().
* internal.h (rb_async_bug_errno): add decl. of above func.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Make "buff" as static. (Maybe) "buff" can be shared between
any caller (any threads) because no one use the read values.
And remove const value "buff_size", and define CCP_READ_BUFF_SIZE
macro.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
no waiting thread. If there are 2 or more runnable threads,
the timer thread does polling. Avoid polling makes power save
for several computers (0.2W per a Ruby process, when I measured).
If outside-event such as signal or Thread#kill was occuerred
when the timer thread does not do polling, then wake-up
the timer thread using communication-pipe (the timer thread
waits this communication-pipe with select(2)).
The discussion about this modification can be found from the post
[ruby-core:33456] and other related posts.
Note that Eric Wong and KOSAKI Motohiro give us the huge
contributions for this modification. Thanks.
* thread_pthread.c (rb_thread_wakeup_timer_thread): add a function.
This function wakes up the timer thread using communication-pipe.
* thread.c (rb_thread_stop_timer_thread): add a parameter which
specify closing communication-pipe or not.
* thread.c (rb_thread_terminate_all): do not stop timer thread here
(ruby_cleanup() terminate timer thread).
* signal.c: wake up timer thread using
rb_thread_wakeup_timer_thread() from signal handler.
* eval.c (ruby_cleanup): use rb_thread_stop_timer_thread(1).
* process.c: use rb_thread_stop_timer_thread(0)
(reuse communication-pipe).
* thread_win32.c (rb_thread_wakeup_timer_thread): add a dummy
function.
* vm_core.h: add and fix decl. of functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c: remove HAVE_GVL_YIELD macro.
* thread_win32.c (gvl_yield): new. this fallback logic was moved from
rb_thread_schedule_rec().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32069 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
When native_cond_timedwait() return 0 by spurious wakeup, we
don't have to neither 1) call timer_thread_function and 2)
exit the timer thread.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
this is a regression since r31457. [Bug #4808] [ruby-dev:43606]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31893 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
of malloc.
* thread_pthread.c (remove_signal_thread_list): use xfree instead
of free.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1) we don't have to use #ifdef FOO-PLATFORM directly 2) About
half #ifdef didn't care symbian properly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (native_cond_timeout): new internal api.
it calculate a proper time for argument of native_cond_timedwait().
* thread_win32.c (native_cond_timeout): ditto.
* thread_pthread.c (thread_timer): use native_cond_timeout()
instead of get_ts.
* thread.c (lock_func): ditto.
* thread_pthread.c (get_ts): removed. use native_cond_timeout().
* thread.c (init_lock_timeout): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
no longer an alias of pthread_cond_t.
* thread_pthread.c: adapt new rb_thread_cond_t type.
* thread.c (mutex_alloc): ditto.
* thread_win32.c (native_cond_initialize): ditto.
* configure.in: add check for pthread_cond_attr_setclock() and
clockid_t type.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
We don't have to call mutex_unlock() before initialize it!
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
APIs to modularize GVL implementation.
* thread_pthread.c, thread_pthread.h: Two GVL implementations.
(1) Simple locking GVL which is same as existing GVL.
(2) Wake-up queued threads. The wake-up order is simple FIFO.
(We can make several queues to support exact priorities, however
this causes some issues such as priority inversion and so on.)
This impl. prevents spin-loop (*1) caused on SMP environemnts.
*1: Only one Ruby thread acqures GVL again and again.
Bug #2359 [ruby-core:26694]
* thread_win32.c, thread_win32.h: Using simple lock
not by CRITICAL_SECTION but by Mutex.
Bug #3890 [ruby-dev:42315]
* vm.c (ruby_vm_destruct): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e