[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Thread#stop

Joel VanderWerf

2/10/2006 4:11:00 AM


Is it possible for one thread to put another thread in a stop (or sleep)
state? (Unlike Thread.stop which stops the current thread.)

The answer is currently no (Thread#stop was removed at one point), and
Matz has said he doesn't think this should be allowed:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-...

But what about this case:

I've got a threaded app with a DRb-based remote debugging/control
interface. I want to stop all non-DRb threads when the user sends the
"stop" command. The the user (or other external process) can then send
more commands to the DRb interface and inspect stuff without those
threads running around like crazy. Then a later call to the DRb
interface can wakeup all the threads that got stopped.

I can't use Thread.critical, because the DRb interface has to stay awake
for the next request. None of the threads in the DRb group should be
stopped.

Setting the priority of the non-DRb threads very low doesn't seem to
work either--they keep running when the DRb threads are not running.

Any ideas? If Thread#stop is a bad idea, what is the right idea in this
case?

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


6 Answers

David Vallner

2/10/2006 1:56:00 PM

0

Dna Piatok 10 Február 2006 05:10 Joel VanderWerf napísal:
> Any ideas? If Thread#stop is a bad idea, what is the right idea in this
> case?

Letting threads directly play tricks on each other is more of a Q'n'D hack
than a real parallelism solution. What you're looking for sounds like a latch
construct that the user process opens and closes for the other threads. Brief
googling indicates you could use something called a read-write mutex / lock.

Maybe there's a ruby implementation out there already, if not, it should be
doable via Mutexes and Semaphores. (Do we have Semaphores in the core or
stdlib?)

David Vallner


Joel VanderWerf

2/10/2006 8:30:00 PM

0

David Vallner wrote:
> Dna Piatok 10 Február 2006 05:10 Joel VanderWerf napísal:
>> Any ideas? If Thread#stop is a bad idea, what is the right idea in this
>> case?
>
> Letting threads directly play tricks on each other is more of a Q'n'D hack
> than a real parallelism solution. What you're looking for sounds like a latch
> construct that the user process opens and closes for the other threads. Brief
> googling indicates you could use something called a read-write mutex / lock.
>
> Maybe there's a ruby implementation out there already, if not, it should be
> doable via Mutexes and Semaphores. (Do we have Semaphores in the core or
> stdlib?)
>
> David Vallner
>

I agree that Thread#stop is not a good tool for writing concurrency
constructs, and Thread.stop should be used instead, as it is in the
implementations of Mutex et al. Thread#stop is bad because the stopped
thread can be stopped in a way that the thread cannot predict or control
(except that it can prevent being stopped by being in Thread.critical).
But that's exactly why I want it.

Think of this as a remote debugger (in fact, it is). I need all threads
to stop wherever they are except the ones being used to debug the
process. If there were a Thread.critical that applied to all threads in
the DRb ThreadGroup, I'd be happy.

As I understand it, a latch would not serve this purpose. A latch stops
newly created threads from running until the latch is opened. In ruby
this would be easy to implement using Thread.stop within the block of
each thread. Then another thread can wakeup those threads as needed:

th = Thread.new { Thread.stop; do_some_work }
prepare_for_th_to_run
th.wakeup



--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


David Vallner

2/12/2006 3:58:00 AM

0

Dna Piatok 10 Február 2006 21:29 Joel VanderWerf napísal:
> As I understand it, a latch would not serve this purpose. A latch stops
> newly created threads from running until the latch is opened. In ruby
> this would be easy to implement using Thread.stop within the block of
> each thread. Then another thread can wakeup those threads as needed:
>
> th = Thread.new { Thread.stop; do_some_work }
> prepare_for_th_to_run
> th.wakeup

For some strange reason I thought you were using looping worker threads with
short execution time. Ah well.

David Vallner


Joel VanderWerf

2/12/2006 7:47:00 AM

0

David Vallner wrote:
> Dna Piatok 10 Február 2006 21:29 Joel VanderWerf napísal:
>> As I understand it, a latch would not serve this purpose. A latch stops
>> newly created threads from running until the latch is opened. In ruby
>> this would be easy to implement using Thread.stop within the block of
>> each thread. Then another thread can wakeup those threads as needed:
>>
>> th = Thread.new { Thread.stop; do_some_work }
>> prepare_for_th_to_run
>> th.wakeup
>
> For some strange reason I thought you were using looping worker threads with
> short execution time. Ah well.

Well, some are fairly short lived, but those ones are fired off by some
"permathreads". In fact, the are so perma that they have a big rescue
clause with a retry (for StandardErrors) around everything they do.

Still wish I knew how to "freeze frame" all the threads, except the drb
threads that are inspecting them...

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


Christopher Helms

8/12/2009 1:40:00 AM

0

On Aug 11, 8:03 pm, "zzbun...@netscape.net" <zzbun...@netscape.net>
wrote:
> On Aug 11, 7:23 pm, Christopher Helms <Chrishelms...@yahoo.com> wrote:
>
>
>
> > On Aug 11, 6:12 am, *elation* wrote:
>
> > > August 11, 2009
>
> > > WASHINGTON (Reuters) – U.S. House leaders have dropped plans to spend
> > > $550 million in the Air Force budget on passenger jets used by
> > > lawmakers and senior government officials, officials said on Monday.
>
> > > The House of Representatives reversed the move to upgrade the
> > > executive jet fleet after public criticism, opposition from other
> > > lawmakers and the Defense Department had said it did not need more
> > > planes that it had requested.
>
> > > "If the Department of Defense does not want these aircraft, they will
> > > be eliminated from the bill," Representative John Murtha, chairman of
> > > a House panel on defense appropriations, said in a statement.
>
> > > A spokesman for House Speaker Nancy Pelosi said she supports the
> > > decision.
>
> > > Before leaving for the August congressional recess, the House approved
> > > a Defense Appropriation bill for fiscal year 2010 that included $550
> > > million for three Gulfstream jets and five military versions of a
> > > Boeing 737.
>
> > > The Pentagon's original request was $220 million to purchase one
> > > Gulfstream plane and three Boeing Co. aircraft.
>
> > > Murtha, a Pennsylvania Democrat, said the four additional planes his
> > > subcommittee ordered would have replaced older aircraft that have
> > > safety and maintenance issues.
>
> > What happens when there isn't any more money to borrow?
>
>    Well, these idiots know so little about economics, other than
> passenger jets,
>    the people with more than shit for brains long ago, like going on
> 70 years
>    transitioned into AI, Digital Computers, DSP, Cellular
> Communications,
>    Fiber :Optics Systems, Laser and Maser Systems, Laser Disks, and
> Holographics,
>    Communication Satellites, Weather Sattellites, GPS, Digital Terrain
> Mapping,
>    Data Fusion, Cruise Missiles, Drones, Phalanx, UAVs, AAVs
>    Micowave Systems, like Micowave Ovens, Microwave Cooling, and
> similar things.
>    Microelectronics, Electronic Books, Intergrated Circuits, Nano-
> Tech, Desktop Publishing,
>    On-Line Banking, On-Line Shopping, HDTV and On-Line Publishing.
>    Modernized Gas Turbine Systems, Solar Energy, Pv Cell Energy, neo
> Wind Energy,
>    Biodiesel, Self-Replicating Machines, and Self-Assembling Robots.
>
>    So, the only thing you can really say for the idiots anymore, is if
> they have
>    to borrow money, they'll have to borrow it from Nigeria. Since
> Nigeria is one of
>    the few countries that still loans crude oil to idiots.


We're already 300 billion over our previous over-budget projections.
Did Reagan ever even have a 300 billion dollar annual budget for the
whole country? and Reagan caught all kinds of hell for running
deficits. I have no idea where all this money is supposed to be coming
from, but if we don't stop blowing through money like this, at some
point some law of economics is going to do it for us. This simply
cannot go on much longer. Not only is there not enough money in the
country, there isn't enough money on the planet.

zzbunker@netscape.net

8/12/2009 3:05:00 AM

0

On Aug 11, 9:40 pm, Christopher Helms <Chrishelms...@yahoo.com> wrote:
> On Aug 11, 8:03 pm, "zzbun...@netscape.net" <zzbun...@netscape.net>
> wrote:
>
>
>
>
>
> > On Aug 11, 7:23 pm, Christopher Helms <Chrishelms...@yahoo.com> wrote:
>
> > > On Aug 11, 6:12 am, *elation* wrote:
>
> > > > August 11, 2009
>
> > > > WASHINGTON (Reuters) – U.S. House leaders have dropped plans to spend
> > > > $550 million in the Air Force budget on passenger jets used by
> > > > lawmakers and senior government officials, officials said on Monday.
>
> > > > The House of Representatives reversed the move to upgrade the
> > > > executive jet fleet after public criticism, opposition from other
> > > > lawmakers and the Defense Department had said it did not need more
> > > > planes that it had requested.
>
> > > > "If the Department of Defense does not want these aircraft, they will
> > > > be eliminated from the bill," Representative John Murtha, chairman of
> > > > a House panel on defense appropriations, said in a statement.
>
> > > > A spokesman for House Speaker Nancy Pelosi said she supports the
> > > > decision.
>
> > > > Before leaving for the August congressional recess, the House approved
> > > > a Defense Appropriation bill for fiscal year 2010 that included $550
> > > > million for three Gulfstream jets and five military versions of a
> > > > Boeing 737.
>
> > > > The Pentagon's original request was $220 million to purchase one
> > > > Gulfstream plane and three Boeing Co. aircraft.
>
> > > > Murtha, a Pennsylvania Democrat, said the four additional planes his
> > > > subcommittee ordered would have replaced older aircraft that have
> > > > safety and maintenance issues.
>
> > > What happens when there isn't any more money to borrow?
>
> >    Well, these idiots know so little about economics, other than
> > passenger jets,
> >    the people with more than shit for brains long ago, like going on
> > 70 years
> >    transitioned into AI, Digital Computers, DSP, Cellular
> > Communications,
> >    Fiber :Optics Systems, Laser and Maser Systems, Laser Disks, and
> > Holographics,
> >    Communication Satellites, Weather Sattellites, GPS, Digital Terrain
> > Mapping,
> >    Data Fusion, Cruise Missiles, Drones, Phalanx, UAVs, AAVs
> >    Micowave Systems, like Micowave Ovens, Microwave Cooling, and
> > similar things.
> >    Microelectronics, Electronic Books, Intergrated Circuits, Nano-
> > Tech, Desktop Publishing,
> >    On-Line Banking, On-Line Shopping, HDTV and On-Line Publishing.
> >    Modernized Gas Turbine Systems, Solar Energy, Pv Cell Energy, neo
> > Wind Energy,
> >    Biodiesel, Self-Replicating Machines, and Self-Assembling Robots.
>
> >    So, the only thing you can really say for the idiots anymore, is if
> > they have
> >    to borrow money, they'll have to borrow it from Nigeria. Since
> > Nigeria is one of
> >    the few countries that still loans crude oil to idiots.
>
> We're already 300 billion over our previous over-budget projections.
> Did Reagan ever even have a 300 billion dollar annual budget for the
> whole country? and Reagan caught all kinds of hell for running
> deficits. I have no idea where all this money is supposed to be coming
> from, but if we don't stop blowing through money like this, at some
> point some law of economics is going to do it for us. This simply
> cannot go on much longer. Not only is there not enough money in the
> country, there isn't enough money on the planet.- Hide quoted text -

Welll, that doesn't matter with thieves, so the people with non-zero
educations
mostly stopped giving a crap either way. Since the stooges don't
couny such
mundane things as money in their imbeciles economics anymore.
It's all done with smoke, mirrors, six-shooters, pep-rallies,
whistles, whoopie cushions,
magic farts, and game theory.




>
> - Show quoted text -