-----Original Message-----
From: Donald Sharp [mailto:sharpd / cisco.com]
Sent: Tuesday, March 20, 2001 12:47 PM
To: ruby-talk ML
Subject: [ruby-talk:12977] Re: Native/pthreads in Ruby


On Tue, Mar 20, 2001 at 05:34:27PM +0900, Yukihiro Matsumoto wrote:
> Hi,
>
> In message " Native/pthreads in Ruby"
>     on 01/03/20, Christopher Petrilli <petrilli / amber.org> writes:
>
> |I read everything I could find in the archives talking about
> |implementing pthreads in Ruby, and I'm wondering if anyone has started
> |on this.  I'm working on a project which is pretty I/O intensive and
> |this would help enormously in writing a fast version.  I'm currently
> |working to convert the code from Python (which uses pthreads), and I'm
> |running into that wall.
> |
> |Ideas?
>
> The conservative GC which Ruby is using does not work well with
> pthreads.  Unfortunately pthread does not provide the way to get stack
> boundary of each thread.  You have to restrict Ruby interpreter to be
> run on only one thread to get along with native threads.

Sure it does through these calls:

pthread_attr_setstackaddr();
pthread_attr_getstackaddr();
pthread_attr_setstacksize();
pthread_attr_getstacksize();

You should set the stack and then do a pthread_create()...

donald
>
> 							matz.
>

These are optional interfaces to the standard, and are not guarranteed to be
implemented.  Linux and Solaris 2.x do appear to support this, but you are
not guarranteed that it will be available on other operating systems.
However, writing portable code using these interfaces is generally held to
be very difficult if possible at all. [Butenhof, 1997]

From cursory inspection of the source code Ruby appears to use a
conservative Mark-Sweep garbage collector.  This would require all threads
that my potentially 'mutate' the heap be suspended before the garbage
collector runs, and remain suspened until it has finished.  POSIX threads
does *not* provides mechanism by which threads may be suspended without
cooperation. [LinuxThreads, 2001]

From personal experience I know it is possible to force all threads in a
program to poll on semaphore, but it is not without clear drawbacks.  I
cannot know how easy it would be to implement this or another scheme in the
ruby interpreter.  Clearly Matsumoto-san is the appropriate judge of such
issues.

Garbage collection and Threading are of interest to me and I would be happy
to discuss in more detail with like minded list participants.

Marc

Butenhof, 1997
  Programming with POSIX Threads, Addison-Wesley, p138

LinuxThreads, 2001
  http://pauillac.inria.fr/~xleroy/linuxthradfs/faq.html#E