For Programmers: Free Programming Magazines  


Home > Archive > ithreads > July 2007 > perl and threads









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author perl and threads
kristoff bonne

2006-07-18, 7:08 pm

Aan allen die zijn of zullen zijn, onze groet.



I don't know if this is the correct place for "user"-discussion, but I'm
looking for some information about perl threads.

I've been looking into perlthrtut and the other manuals for this, but I
don't see to find the solution.

If it is off-topic, please point me to a more correct newsgroup or forum.




My question is this:

Is there a way to get 100 % certainty if a thread is running.


What I want to do is this:

I have a program that makes a number (actually eigth) of ssh-sessions to
a number of servers using the net::telnet module. On the servers, they
read the log-files to get some information using a "tail -f".


Now, I've got a thread (called "sshmaster") in my main program which
starts up the 8 ssh-session (called "sshsession"); each as a seperate
thread.
These sub-thread communicate back to "sshmaster" for control-messages
(e.g. connection established, connection failed, connection interrupted)
using a queue.



So far, so good. And it does seams to work pretty-much OK, ... as long
as the ssh-sessions behaviour as they are supposted to do.


But, I want to be sure that the sub-threads do keep on working OK, and
-when a subtreads dies for whatever reason- that "sshmaster" is able to
check this.

I see different possibilities:
1/ sent a control-message from the sub-thread to sshmaster over the
message-queue. However, this will not work if the subthread dies for an
unknown reason and it might not be able to sent a message to sshmaster.

2/ lock a variable (which will automatically unlock when the thread
dies), but sshmaster is not able to check if a variable is still locked
without blocking.

3/ As "sshmaster" has a list of all its subthreads, ask a system if a
thread is still alive. But HOW????


The only way I see is by locking a file using the "flock" mechanism but
that'a a bit "overkill" if you ask me.


Anybody any other ideas?






B.T.W. Appart from the "check if thread still runs" and "check if a
variable is locked without locking it yourself and without blocking",
there are two other things I would like to use, but for which I have not
found a solution:

- be able to read from multiple queues at the same time.
- or, as an option, add a "time-out" option to the "dequeue" function.
When you have a thread that runs by itself doing some action and
communicating with other threads over queues, you usually have multiple
queues active (e.g. one for the "data" and another one for
"control-messages").

Currently, you have to do this using "dequeue_nb" and "sleep".


- Sent a "kill" to a thread. (e.g.where the "sshmaster" can kill of a
child sub-thread when it sees it has not received any information from
that sub-thread for -say- 60 seconds.


- set up a queue as a "pipe" between just two processes; and where -if
one of the sides dies- the process on the other side gets notifed of
this fact.



Just my 2 eurocent.



Cheerio! Kr. Bonne.
Jerry D. Hedden

2006-07-18, 7:08 pm

> Is there a way to get 100 % certainty if a thread is running.

Yes. Install the lastest version of 'threads' from CPAN. Then you can
use $thr->is_running().

Kristoff Bonne

2006-07-19, 4:11 am

Jerry,

Jerry D. Hedden schreef:
[color=darkred]
> Yes. Install the lastest version of 'threads' from CPAN. Then you can
> use $thr->is_running().


Thanks.

In the meanwhile, I find no less then three possibilities.

Appart from your proposal, I found the "threads::running" library here:
http://search.cpan.org/~elizabeth/Thread-Running-0.07/


And later, somebody proposed Thread::State (see here:
http://search.cpan.org/~makamaka/Th...Thread/State.pm)


Isn't it great when you have choice. :-)



Cheerio! Kr. Bonne.
Enceertented46

2007-04-17, 6:10 pm

http://Celine-Dion-facestanding-mov...hp?movie=148803
Oogy

2007-04-22, 10:53 am

http://Katie-Holmes-touching-her-bo...hp?movie=148803
Potard

2007-06-11, 7:11 pm

Paula Abdul Shows Juicy Knockers!

http://www.reyrewh.com/MediaPlayer?clip=1673286



free online lesbian sex video download free long sex video rough anal sex video free latin sex video couple homemade sex video
http://343-sex-video.info/mature-wife-sex-video.html http://343-sex-video.info/mature-home-sex-video.html http://343-sex-video.info/free-cele...video-clip.html http://343-sex-video.info/celebrity-clip-sex-video.html http://343-sex-video.info/clip-daily-sex-video.html
Cruza

2007-07-05, 4:10 pm

Angelina Jolie and Alyssa Milano Vibrating In Slits!
http://www.britneyraped.com/WatchTube?vid=726648
Adermoterup

2007-07-10, 9:01 pm

Cameron Diaz and Catherine Z. Jones Seducing Waitress!
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com