[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Weird deadlock problems with Slave/drb

Peter Lichten

6/29/2007 9:23:00 PM

#!/usr/bin/env ruby

# Original program idea:
# Write a ruby program that checks the integrity of all my FLAC music
files,
# and that makes use of my MacBooks Core Duo CPU. Since Ruby doesn't
support
# native threadds, I decided to use the Slave library.
#
# Problem:
# I start 3 Slave servers:
# worker1 and worker2 both query the filename server to get the next
filename
# to process.
#
# On Mac OS 10.4.10, ruby 1.8.6 (Locomotive or MacPorts, same problem)
the second
# worker server process never starts, it seems to sleep forver, and I
don't
# see my programming mistake.
#
# The same problem occurs on Ubuntu Feisty.
#
# However: IF you start the 2nd worker after the first worker completed
its
# work, it runs without problem.
#
# And: If you disable the call to the filename server, both workers run
# in parallel, too, without deadlocking.
#
# So the problem has something to do with both workers trying to access
the
# same filename server.
#
# Any ideas?

require 'slave'
require 'monitor'
require 'fastthread'

class FlacTestServer

def processFiles(filenameServer)
50.times do |i|
#sleep(0.02)
#Activate this:
#puts("PID #{ Process.pid }: Iteration #{ i }")
#and disable this and both workers will run without worker 2
sleeping forever.
puts("#{ Process.pid }: #{ filenameServer.nextFilename() }")
end
end
end

class FilenameServer
include MonitorMixin

def initialize()
super
@counter = 0
end

def nextFilename()
synchronize do
# Return some dummy data
@counter += 1
"#{ Process.pid }, #{ @counter }"
end
end
end


if $0 == __FILE__

fnServer = Slave.new() { FilenameServer.new() }.object

worker1 = Slave.object({:async => true, :psname => 'Worker1'}) {
FlacTestServer.new().processFiles(fnServer) }

# "Works" if you activate this:
#worker1.join()

worker2 = Slave.object({:async => true, :psname => 'Worker2'}) {
FlacTestServer.new().processFiles(fnServer) }

# If you create the slaves using the following method instead, worker2
sometimes runs, sometimes not
# and sometimes it runs only a few internal iterations before it
sleeps forever / deadlocks...?!?
# But you can get it to work if you active the sleep call in line 37.
#ftServer1 = Slave.new() { FlacTestServer.new() }.object()
#ftServer2 = Slave.new() { FlacTestServer.new() }.object()
#
#worker1 = Thread.new() { ftServer1.processFiles(fnServer) }
#worker2 = Thread.new() { ftServer2.processFiles(fnServer) }

worker1.join()
puts("Worker 1 terminated.")

#puts("Worker 2 status: #{ worker2.status() }") until
worker2.join(0.15)
worker2.join()
puts("Worker 2 terminated.")

puts("End main program: #{Process.pid}")
end

--
Posted via http://www.ruby-....

3 Answers

Donn Messenheimer

9/1/2012 3:50:00 PM

0

On 9/1/2012 6:20 AM, Free Lunch wrote:
> On Fri, 31 Aug 2012 19:52:01 -0700, Donn Messenheimer
> <wieber.blows@taft_sucks.org> wrote in alt.atheism:
>
>> On 8/31/2012 7:26 PM, Free Lunch wrote:
>>> On Fri, 31 Aug 2012 18:10:43 -0700, Donn Messenheimer
>>> <wieber.blows@taft_sucks.org> wrote in alt.atheism:
>>>
>>>> On 8/31/2012 5:46 PM, Free Lunch wrote:
>>>>> On Fri, 31 Aug 2012 16:32:56 -0700, Donn Messenheimer
>>>>> <wieber.blows@taft_sucks.org> wrote in alt.atheism:
>>>>>
>>>>>> On 8/31/2012 4:24 PM, Free Lunch wrote:
>>> ...
>>>>>>> Name them.
>>>>>>
>>>>>> You have some belief about the existence of a deity. You believe there
>>>>>> is a deity, or you believe there is no deity, or you don't believe there
>>>>>> is a deity. All three are possible categorizations concerning your
>>>>>> belief regarding a deity, and that makes them religious beliefs.
>>>>>
>>>>> Only to those who understand. [full stop; period]
>>>>
>>>> Exactly.
>>>
>>> Correct.
>>
>> Correct.
>
> How many times will you attempt to defend your failed claims

Never - they're not "failed".

skink on sink

9/1/2012 4:26:00 PM

0

On 9/1/2012 12:49 AM, Yap wrote:
> On Sep 1, 10:26 am, skink on sink<l...@ar.ds> wrote:
>> On 8/31/2012 6:46 PM, Free Lunch wrote:
>>
>>> On Fri, 31 Aug 2012 18:38:04 -0600, skink on sink<l...@ar.ds> wrote in
>>> alt.atheism:
>>
>>>> On 8/31/2012 4:31 PM, Free Lunch wrote:
>>>>> I have no religious beliefs. Those are my beliefs about religion.
>>
>>>> Liar.
>>
>>> Show me.
>>
>> You are opposed to religion, true?
>
> Is opposing religion or superstition wrong?

Nope.

> The religion cults get their vast fortunes from tithers, depriving the
> money into poverty eradication.

Whatever...

> Of course suckers like you think that is OK or not his business.

That's not the point, you are off topic.

?pam?u?ter

9/1/2012 9:16:00 PM

0

--
SPAMMED INTO NON-RELEVANT NEWSGROUPS - AND CUT



"Aunt Six of Nine or Half-dozen of the Other of the Borg" <six-nine@borgcollective.gov>
wrote in message news:six-nine-84EA31.01032001092012@news.eternal-september.org...