[Newbies] BlockClosure>>fork problem

Ron Teitelbaum Ron at USMedRec.com
Tue Feb 20 20:53:38 UTC 2007


Ohhhhh I'm really sorry.  It's funny now that I go back and look I'm
surprised that I missed that.  That's a horse of a different color.  

Basically to answer your question Transcript is not thread safe.  I'm not
sure exactly where it goes wrong but I suspect that it is probably doing a
copy somewhere and if one collection is used as a source and is copied at
the same time with two new additions then one gets lost.

To fix that you can set a semaphore which basically says don't try to access
Transcript from two places at exactly the same time.

semaphore := Monitor new.
[10 timesRepeat: [semaphore critical: [Transcript show: '2']]] fork.
[10 timesRepeat: [semaphore critical: [Transcript show: '1']]] fork.
Transcript cr.

This should make transcript thread safe.

Hope that helps, 

Ron Teitelbaum

> -----Original Message-----
> From: beginners-bounces at lists.squeakfoundation.org [mailto:beginners-
> bounces at lists.squeakfoundation.org] On Behalf Of George Herolyants
> Sent: Tuesday, February 20, 2007 3:28 PM
> To: A friendly place to get answers to even the most basic questions
> aboutSqueak.
> Subject: Re: [Newbies] BlockClosure>>fork problem
> Thanks for this answer, Ron. But actually I'm not confused with order in
> wich '1' and '2' presents in result line. I can't understand why in some
> cases this code results ten '1' and ten '2' and in some cases it results
> ten '2' and only nine '1'?
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

More information about the Beginners mailing list