[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

thread safty

uncutstone

5/14/2006 7:40:00 AM

Where to get information about whether a class in ruby standard library
is thread-saft?

For example, is Logger thread safe? Where to find this kind of info?

9 Answers

Robert Klemme

5/14/2006 11:06:00 AM

0

uncutstone wrote:
> Where to get information about whether a class in ruby standard library
> is thread-saft?
>
> For example, is Logger thread safe? Where to find this kind of info?

IMHO you're safe when assuming that no class is thread safe by itself.
Java went down the road of making collections thread safe by default
(Vector, Hashtable) and they corrected their error later (ArrayList,
HashMap). It's usually a bad idea to make general purpose classes
thread safe because you pay the overhead always even if it's not needed.
Also, for many use cases it's not sufficient to just synchronize
methods. For example, if you check whether a hash contains a certain
key and then act differently depending on whether the key is there or
not you need external synchronization anyway.

Kind regards

robert

uncutstone

5/14/2006 12:55:00 PM

0

Thanks for the explanation.

uncutstone

5/15/2006 4:13:00 AM

0

This is discussion about "A tricky problem about Process.wait and popen
" . I post it here because I cannot post it in that thread. Maybe it
is full. I don't know.

Robert Klemme write:

> Then place a loop into the thread block.
> No, you probably did not understand my code fully: it waits for all
> *threads* to terminate! The script creates PARALLEL (i.e. 10) threads
> and each of them forks a ruby process and terminates once the child
> process has terminated. So you got 10 processes executing in parallel
> and the script waits for all to terminate.

Yes , it works and I fully understood your code. :-)
>
> I don't think you need DRb for this. It seems the number of child
> processes is an input parameter. You just need to add that to my
> script. Then decrement a counter thread safe and have each thread start
> a new process as long as you are not done. It's an easy change to the
> script I provided earlier.

IMHO, I think DRb has some advantage when there is lots of info to
transfer between processes that's just what I want. The code I listed
earlier was simplified so you cannot see that. By using DRb, the code
is more concise, simpler and easier to understand.

Thanks, it is my pleasure to discuss with you .

Robert Klemme

5/15/2006 7:09:00 AM

0

uncutstone wrote:
> This is discussion about "A tricky problem about Process.wait and popen
> " . I post it here because I cannot post it in that thread. Maybe it
> is full. I don't know.

Um... Since this is a usenet newsgroup I don't think it can ever be
"full". I'm not sure what problems you are experiencing. Maybe they
are related to the fact that you're posting from China.

> Robert Klemme write:
>
>> Then place a loop into the thread block.
>> No, you probably did not understand my code fully: it waits for all
>> *threads* to terminate! The script creates PARALLEL (i.e. 10) threads
>> and each of them forks a ruby process and terminates once the child
>> process has terminated. So you got 10 processes executing in parallel
>> and the script waits for all to terminate.
>
> Yes , it works and I fully understood your code. :-)

Ok, fine.

>> I don't think you need DRb for this. It seems the number of child
>> processes is an input parameter. You just need to add that to my
>> script. Then decrement a counter thread safe and have each thread start
>> a new process as long as you are not done. It's an easy change to the
>> script I provided earlier.
>
> IMHO, I think DRb has some advantage when there is lots of info to
> transfer between processes that's just what I want. The code I listed
> earlier was simplified so you cannot see that. By using DRb, the code
> is more concise, simpler and easier to understand.

Ah, I see. Yes in that case the DRb approach is probably better. In
that case I'd still use fork with a block to spawn child processes - the
big advantage is that you do not have to fiddle with path information
(e.g. if "ruby" is not on your path) and you do not have to transfer
information (i.e. DRb port number) via command line arguments. It may
or may not be a disadvantage to have all the code in one script - that
depends; OTOH if it's larger then it's probably reasonable to place
classes in separate files anyway.

> Thanks, it is my pleasure to discuss with you .

Ditto.

Kind regards

robert

uncutstone

5/15/2006 8:48:00 AM

0


Robert Klemme wrote:

> Ah, I see. Yes in that case the DRb approach is probably better. In
> that case I'd still use fork with a block to spawn child processes - the
> big advantage is that you do not have to fiddle with path information
> (e.g. if "ruby" is not on your path) and you do not have to transfer
> information (i.e. DRb port number) via command line arguments. It may
> or may not be a disadvantage to have all the code in one script - that
> depends; OTOH if it's larger then it's probably reasonable to place
> classes in separate files anyway.
>

Yes,fork with a block is really better. By using fork, I don't need to
consider the extra path dependency problem, I don't need to transfer
arguments to child process via command line.

But I am sorry that fork is not supported on my out-of-date windows 98
, a 350MHz one. It seems that I have to upgrade my PC now. It gives me
more and more troubles. For example, I cannot install VMWare on windows
98 too.

FYI, below is the result of using fork on my machine:
irb(main):001:0> fork {puts "hello"}
NotImplementedError: The fork() function is unimplemented on this
machine
from (irb):1:in `fork'
from (irb):1

Robert Klemme

5/15/2006 9:47:00 AM

0

uncutstone wrote:
> Robert Klemme wrote:
>
>> Ah, I see. Yes in that case the DRb approach is probably better. In
>> that case I'd still use fork with a block to spawn child processes - the
>> big advantage is that you do not have to fiddle with path information
>> (e.g. if "ruby" is not on your path) and you do not have to transfer
>> information (i.e. DRb port number) via command line arguments. It may
>> or may not be a disadvantage to have all the code in one script - that
>> depends; OTOH if it's larger then it's probably reasonable to place
>> classes in separate files anyway.
>>
>
> Yes,fork with a block is really better. By using fork, I don't need to
> consider the extra path dependency problem, I don't need to transfer
> arguments to child process via command line.
>
> But I am sorry that fork is not supported on my out-of-date windows 98
> , a 350MHz one. It seems that I have to upgrade my PC now. It gives me
> more and more troubles. For example, I cannot install VMWare on windows
> 98 too.
>
> FYI, below is the result of using fork on my machine:
> irb(main):001:0> fork {puts "hello"}
> NotImplementedError: The fork() function is unimplemented on this
> machine
> from (irb):1:in `fork'
> from (irb):1


It works on cygwin

09:38:33 [~]: ruby -e 'fork { puts "hello" }'
hello
11:45:50 [~]: uname -a
CYGWIN_NT-5.2-WOW64 PDBXPWSRK38 1.5.19(0.150/4/2) 2006-01-20 13:28 i686
Cygwin


Upgrading is certainly a good idea. :-)

robert

Poetic Justice

9/23/2008 9:44:00 PM

0

Sid9 wrote:
> "ZNUYBV" <tjwilson6531@gmail.com> wrote in message
> news:cb991666-0630-45e0-ac19-9e348737583b@r15g2000prd.googlegroups.com...
>> On Sep 23, 8:15 am, "Lick Lick" <R...@wh.net> wrote:
>>> Tell your conservative friends....
>>> that when they go to the polls on Election Day, they should remember one,
>>> undeniable fact: It was the Republicans that did this to you.
>>>
>>> Once George W. Bush is out of office come January 20, 2009, we should all
>>> dedicate ourselves to see to it that the murderous little thug is sent to
>>> federal prison - and that he dies there. (Note to the Secret Service: Of
>>> natural causes, of course, dear boys).
>>> Is there anyone out there - so deluded and naive - who still thinks that
>>> sending this idiot to the White House was a good idea?
>>>
>>> "....And that government of the people, by the people, for the people,
>>> shall
>>> not perish from the earth."
>>>
>>> Oh, yeah? We're almost there.
>> We sure don't want government by people like you.
>
> My guess is that you voted
> for this dunce twice...and,
> not having learned anything,
> you will vote for McCain.
>
>
And you voted for Carter and Clinton?



--

http://Talk...
********* Koom-Bay-Ya *********
It's been said that a Communist is just a Socialist - - - with a gun.

Sid9

9/23/2008 9:51:00 PM

0



"*Poetic Justice*" <@http://Poetic-Justice.Talk-n-D... wrote in message
news:EpdCk.35712$rD2.16612@bignews4.bellsouth.net...
> Sid9 wrote:
>> "ZNUYBV" <tjwilson6531@gmail.com> wrote in message
>> news:cb991666-0630-45e0-ac19-9e348737583b@r15g2000prd.googlegroups.com...
>>> On Sep 23, 8:15 am, "Lick Lick" <R...@wh.net> wrote:
>>>> Tell your conservative friends....
>>>> that when they go to the polls on Election Day, they should remember
>>>> one,
>>>> undeniable fact: It was the Republicans that did this to you.
>>>>
>>>> Once George W. Bush is out of office come January 20, 2009, we should
>>>> all
>>>> dedicate ourselves to see to it that the murderous little thug is sent
>>>> to
>>>> federal prison - and that he dies there. (Note to the Secret Service:
>>>> Of
>>>> natural causes, of course, dear boys).
>>>> Is there anyone out there - so deluded and naive - who still thinks
>>>> that
>>>> sending this idiot to the White House was a good idea?
>>>>
>>>> "....And that government of the people, by the people, for the people,
>>>> shall
>>>> not perish from the earth."
>>>>
>>>> Oh, yeah? We're almost there.
>>> We sure don't want government by people like you.
>>
>> My guess is that you voted
>> for this dunce twice...and,
>> not having learned anything,
>> you will vote for McCain.
> And you voted for Carter and Clinton?
>
>

Carter was thirty years ahead of the energy problem.
Republicans wasted thirty years.

Reagan, Republicans and Norquist
screwed America big time.

Clinton left a prosperous, powerful,
respected nation...then Republican
bush,jr fucked up everything.

Now they offer a sickly old man from
the bottom of the barrel for president
and a VP candidate that they've turned
into the "Unknown candidate"

Not withstanding that poor offer, it's
going to be, "The economy, stupid!"




Lick Lick

9/23/2008 10:51:00 PM

0


"ZNUYBV" <tjwilson6531@gmail.com> wrote in message
news:cb991666-0630-45e0-ac19-9e348737583b@r15g2000prd.googlegroups.com...
> On Sep 23, 8:15 am, "Lick Lick" <R...@wh.net> wrote:
>> Tell your conservative friends....
>> that when they go to the polls on Election Day, they should remember one,
>> undeniable fact: It was the Republicans that did this to you.
>>
>> Once George W. Bush is out of office come January 20, 2009, we should all
>> dedicate ourselves to see to it that the murderous little thug is sent to
>> federal prison - and that he dies there. (Note to the Secret Service: Of
>> natural causes, of course, dear boys).
>> Is there anyone out there - so deluded and naive - who still thinks that
>> sending this idiot to the White House was a good idea?
>>
>> "....And that government of the people, by the people, for the people,
>> shall
>> not perish from the earth."
>>
>> Oh, yeah? We're almost there.
>
> We sure don't want government by people like you.

No, you are pleased to get dry fucked by Junior Hogg:

GOP and Bush American Dream Downpayment Act of
2003.

http://www.whitehouse.gov/news/releases/2003/12/20031...