[ruby-core:32789] Re: [Ruby 1.9-Feature#3436] Spawn the timer thread lazily

From: SASADA Koichi <ko1@...>
Date: 2010-10-14 16:09:54 UTC
List: ruby-core #32789
Hi,

(2010/10/14 16:45), Mark Somerville wrote:
>> ex) How to wake up the thread?
>>
>>     check_signal();
>>       <- receive signal at this timing
>>     select(..., infinitely);
> 
> Would this occur if rb_signal_buff_size() > 1 and we process a signal
> with a handler that calls a blocking function?

I can't understand your situation.

My situation is occur if signal received at pointed by <this point>:

thread.c:2504
    BLOCKING_REGION({
        /* !!! <this point> !!! */
	result = select(n, read, write, except, timeout);
	if (result < 0) lerrno = errno;
    }, ubf_select, GET_THREAD());

<this point> is
  "after signal checking" and
  "before calling system call".

>> (2) Performance issue.  Your patch start/kill the timer thread.  In
>> general, the native thread creation/deletion cause some performance issue.
> 
> I assumed (perhaps incorrectly) that the overhead was small enough and
> the creation and deletion uncommon enough that it wouldn't be a problem.

I agree that is it not huge performance issue.

> Perhaps there could be a method of increasing the time the timer thread
> waits if rb_thread_alone() and creation of a new thread could reduce
> this again.

My idea is keep the timer thread sleep infinity while only one thread is
running.

>> I understand your issue.  In fact, I'm considering this problem and
>> seeking the solution in recent months.
> 
> It seems to me that we are attempting different things. I have been
> primarily concerned with reducing/removing CPU wakeups in the
> single-threaded case and falling back to the timer thread when
> multi-threaded. Assuming, I understand you correcly, you appear to be
> trying to remove the timer thread completely.

I think we are aimed to solve same problem.  I also want to reduce CPU
wake up counts.  And currently I think we can't remove timer thread.

-- 
// SASADA Koichi at atdot dot net

In This Thread