On Thu, 16 Nov 2000  23:10:56 +0900, Hugh Sasse Staff Elec Eng wrote:
> On Thu, 16 Nov 2000, hipster wrote:
> 
> > Maybe the async producer/consumer example in
> > http:/www.xs4all.nl/~hipster/lib/ruby/semaphore is of any use? If you
> 
> Yes, that looks good.  It is pretty clear what is going on [and it is
> some years since I learned about semaphores! :-)]
> 
> Is the following patch necessary, do you think?

Yes, this is a good idea. Replace

	threads.push Thread.start{ client i }
with
	threads.push Thread.start{ snooze; client i }

and all threads (probably) print "client 9: ...". Not Good.

	Thanks,
	Michel


> neelix hgs 129 %> gdiff -u semaphore.orig semaphore
> --- semaphore.orig      Thu Nov 16 13:59:00 2000
> +++ semaphore   Thu Nov 16 14:03:03 2000
> @@ -60,7 +60,7 @@
>                 @sem = Semaphore.new 3                  # 3 resources
> available
>  
>                 for i in 0..9 do
> -                       threads.push Thread.start{ client i }
> +                       threads.push Thread.start(i){ |i1| client i1 }
>                 end
>  
>                 threads.each{ |t| t.join }
> neelix hgs 130 %> 
> 
> This is on the basis of Programming Ruby page 114, i.e, that the variable
> i might change "under the nose of" the call to client.   I suppose it
> depends on granularity, and may be a very paranoid approach...