[MacRuby-devel] Questions about Threads

Laurent Sansonetti lsansonetti at apple.com
Fri Apr 17 23:05:20 PDT 2009


Hi Alex,

On Apr 17, 2009, at 8:27 PM, Alex Vollmer wrote:

> Hi folks,
>
> Could someone shed a little light on how threads work in MacRuby?  
> For example, if I do this:
>
> Thread.new do
>  10.times do
>    puts "Hi"
>    sleep 2
>  end
> end
>
> Does this run as a NSThread instance? Also does the MacRuby runtime  
> have the Global Interpreter Lock or are MacRuby threads basically  
> NSThreads?

As of MacRuby 0.4 and trunk, the following will create a native  
(pthread) thread that will run through YARV. It will acquire the YARV  
global lock during Ruby dispatch time (but not Objective-C dispatch  
time) because of thread-safety issues.

The next release of MacRuby will have a different implementation and  
there won't be any global lock anymore, so threads will fully run in  
parallel.

An NSThread is generally the same thing as a pthread, I am not aware  
of any big difference (except that it registers itself to the  
collector, but we do this too). The next release of MacRuby might  
perhaps expose an NSThread object for convenience.

Laurent


More information about the MacRuby-devel mailing list