[Rubycocoa-devel 1125] Re: Application stalls on thread context switches of Ruby

Back to archive index

Laurent Sansonetti lsans****@apple*****
Sat Jul 21 20:32:19 JST 2007


Cool, this explains why the problem didn't occur on my other box,  
which runs 1.8.6.

Thanks a lot for the detective work!

Laurent

On Jul 21, 2007, at 3:59 AM, Satoshi Nakagawa wrote:

> Hi.
>
> The problem seems a bug of ruby 1.8.2.
> I'm sorry for my insufficient testing.
>
> I cut the reproduce code into pure Ruby not using RubyCocoa:
>
>  http://limechat.net/rubycocoa/threaded_socket_test.rb
>
> Then I tested it on ruby 1.8.2 and ruby 1.8.6:
>
>  $ /usr/bin/ruby -v threaded_socket_test.rb
>  ruby 1.8.2 (2004-12-25) [universal-darwin8.0]
>  +++ start writing
>  (stalls)
>
>  $ ruby -v threaded_socket_test.rb
>  ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]
>  +++ start writing
>  *** received
>  (snip)
>  *** received
>  --- end writing
>  *** received
>  (continues normally)
>
> So I concluded it is a bug of ruby 1.8.2, not of RubyCocoa.
>
> Let's release 0.12.0.
>
> --
> Satoshi Nakagawa
>
>
> On 2007/07/21, at 9:08, Satoshi Nakagawa wrote:
>
>> Hi.
>>
>> I found a problem, application stalls on thread context switches of  
>> Ruby.
>> It is reproducible on 0.11.1 and trunk.
>>
>> How to reproduce the problem:
>>
>>  1. Start a socket server.
>>  2. Connect to the server using Ruby's TCPSocket.
>>  3. The server accepts the request.
>>  4. Start a thread on the server, sending 256KB per 5 seconds to  
>> the client.
>>  5. The application stalls. (Rolling rainbow colored cursor forever)
>>
>> Reproduce code in Xcode project:
>>
>>  http://limechat.net/rubycocoa/ThreadedSocketTest.zip
>>
>> In #4, if it sends 64KB per 5 seconds, there are no problem.
>>
>> This is the code around threaded writing from server to client.
>>
>>  def write_loop
>>    loop do
>>      puts '+++ start writing'
>>      @sc.write('a' * (1024 * 256))
>>      puts '--- end writing'
>>      sleep 5
>>    end
>>  end
>>
>> The log when it sends 256KB:
>>
>>  +++ start writing
>>  (stalls)
>>
>> The log when it sends 64KB:
>>
>>  +++ start writing
>>  --- end writing
>>  *** received
>>  *** received
>>  (continues forever)
>>
>> So I noticed the application stops at:
>>
>>  @sc.write('a' * (1024 * 256))
>>
>> It seems to occur on thread context switches of Ruby.
>> Then, I added a logging code to RubyCocoa:
>>
>> Index: framework/src/objc/RBThreadSwitcher.m
>> ===================================================================
>> --- framework/src/objc/RBThreadSwitcher.m       (revision 1928)
>> +++ framework/src/objc/RBThreadSwitcher.m       (working copy)
>> @@ -44,6 +44,7 @@
>> - (void) sched: (NSTimer*)a_timer
>> {
>> +  NSLog(@"@@@ timer");
>>   CHECK_INTS;
>>   if (!rb_thread_critical) rb_thread_schedule();
>> }
>>
>> Then the log is (sends 256KB):
>>
>>  +++ start writing
>>  2007-07-21 08:38:34.247 BridgeTest2[2990] @@@ timer
>>  (stalls)
>>
>> It shows the application stalls after a thread context switch of  
>> Ruby.
>>
>> --
>> Satoshi Nakagawa
>
> _______________________________________________
> Rubycocoa-devel mailing list
> Rubyc****@lists*****
> http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel




More information about the Rubycocoa-devel mailing list
Back to archive index