Sponsored Content
Top Forums Shell Programming and Scripting Perl Threads Terminating Abnormally. Post 302769531 by DGPickett on Tuesday 12th of February 2013 02:54:00 PM
Old 02-12-2013
While there are locks like mutex, I like to use threads in a flow paradign like shell scripts, with pipes or ring buffers from one to the next. On thread can be a dispatcher, writing buffers to many threads, and another might be a collector, reading buffers from many threads. Pipes let your threads block, which is nice as threads should not consume CPU when idle, but who wants to sleep and poll (sleep short and waste CPU, sleep long and add latency)? You can poll() or select() if you have many pipes to block on. Dispatcher and collector could be the same thread, so it can add or remove threads for demand.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Terminating child script with terminating the parent script

Hi I was working on a shell script with randomly shows a page of text from a randomly selected topic .As soon as the page is displayed it callers a timer script which keeps on running indefinitely until the timer script is killed by the user. This is where I have the problem,if I press... (2 Replies)
Discussion started by: mervin2006
2 Replies

2. Shell Programming and Scripting

new to perl.. how do I do this ? fork/ threads ?

I have never coded in perl before (just started today morning :). I need to write a perl program to automate a task. Here is how I do it manually: Start a program in my home dir. Now if I want to execute another program while this one is still running, what I would do is go to another... (6 Replies)
Discussion started by: the_learner
6 Replies

3. UNIX for Advanced & Expert Users

command terminated abnormally

I am getting an Error Message as ============================= starting Sortcl Merging And Aggregation time: command terminated abnormally. ============================= , when running a sortcl command.sortcl is a command for sorting large data,using cosort application installed in... (0 Replies)
Discussion started by: tkbharani
0 Replies

4. UNIX for Advanced & Expert Users

Threads terminating when a signal is generated

hi all, i had created 3 threads using pthreads. Each thread does a different job. Now the main problem is when one thread generates a signal (for example SIGFPE, SIGINT) then the process terminates and all other threads do terminate eventually. I want to keep other threads running i.e, i... (0 Replies)
Discussion started by: skyrulz
0 Replies

5. Shell Programming and Scripting

mpack behaves abnormally

Hi, I was using mpack to send mails using cronjob with attachments. It was working perfect. But recently it's behaving strangely. Its sending the mails without any error message but the mail is not getting delivered. The code I was using: /usr/local/bin/mpack -s "$SUBJECT" -d $MSGBODY... (0 Replies)
Discussion started by: itesh.dash
0 Replies

6. Shell Programming and Scripting

Perl v5.8.5 Threads Problem

Hi Unix gurus, I am facing a threading problem in Perl. I have a worker thread in perl in which I am calling a shell script. The shell script echo's output to the Standard Output from time to time as it progresses. In the worker thread, I am unable to display the echo statement of shell... (1 Reply)
Discussion started by: som.nitk
1 Replies

7. Shell Programming and Scripting

How can i terminating expect script without terminating SSH connection.

Hi all , i know i ask a lot of question but these are really hard to solve and important question. I send two scripts: expect.sh: #!/usr/local/bin/expect spawn ssh root@172.30.64.163 expect "login:" send "root\n" expect "password:" send "root\n^M" interact and son.sh: ... (2 Replies)
Discussion started by: fozay
2 Replies

8. Shell Programming and Scripting

perl launch threads in an array variable?

Im having a problem launching multiple sub routines as threads. My script seems to stop when the first thread is launched. Im condensing the code for simplification here: #!/usr/bin/perl -w use strict; use threads; srand; my ($cnt,$line,$iprange_rand); my... (2 Replies)
Discussion started by: trey85stang
2 Replies

9. HP-UX

logrotate: ALERT exitted abnormally with [127]

HP-UX B.11.23 U 9000/800 636114222 unlimited-user license I see this error in my logs sometimes and have very little info on it... I have searched online for some documentation and haven't been able to find much on this issue. The only thing I found on one site is that if my /tmp folder... (4 Replies)
Discussion started by: zixzix01
4 Replies

10. Shell Programming and Scripting

using threads in perl

Hi everyone, I am trying to create a script which runs a number of processes simultaneously and at the same time use a timer to keep track of what is going on. The problem is that the timer stops and the script exits upon the completion of some of the processes, whereas I want to timer to... (0 Replies)
Discussion started by: free2rhyme2k
0 Replies
Thread(3pm)						 Perl Programmers Reference Guide					       Thread(3pm)

NAME
Thread - Manipulate threads in Perl (for old code only) DEPRECATED
The "Thread" module served as the frontend to the old-style thread model, called 5005threads, that was introduced in release 5.005. That model was deprecated, and has been removed in version 5.10. For old code and interim backwards compatibility, the "Thread" module has been reworked to function as a frontend for the new interpreter threads (ithreads) model. However, some previous functionality is not available. Further, the data sharing models between the two thread models are completely different, and anything to do with data sharing has to be thought differently. With ithreads, you must explicitly "share()" variables between the threads. You are strongly encouraged to migrate any existing threaded code to the new model (i.e., use the "threads" and "threads::shared" modules) as soon as possible. HISTORY
In Perl 5.005, the thread model was that all data is implicitly shared, and shared access to data has to be explicitly synchronized. This model is called 5005threads. In Perl 5.6, a new model was introduced in which all is was thread local and shared access to data has to be explicitly declared. This model is called ithreads, for "interpreter threads". In Perl 5.6, the ithreads model was not available as a public API; only as an internal API that was available for extension writers, and to implement fork() emulation on Win32 platforms. In Perl 5.8, the ithreads model became available through the "threads" module, and the 5005threads model was deprecated. In Perl 5.10, the 5005threads model was removed from the Perl interpreter. SYNOPSIS
use Thread qw(:DEFAULT async yield); my $t = Thread->new(&start_sub, @start_args); $result = $t->join; $t->detach; if ($t->done) { $t->join; } if($t->equal($another_thread)) { # ... } yield(); my $tid = Thread->self->tid; lock($scalar); lock(@array); lock(%hash); my @list = Thread->list; DESCRIPTION
The "Thread" module provides multithreading support for Perl. FUNCTIONS
$thread = Thread->new(&start_sub) $thread = Thread->new(&start_sub, LIST) "new" starts a new thread of execution in the referenced subroutine. The optional list is passed as parameters to the subroutine. Execution continues in both the subroutine and the code after the "new" call. "Thread->new" returns a thread object representing the newly created thread. lock VARIABLE "lock" places a lock on a variable until the lock goes out of scope. If the variable is locked by another thread, the "lock" call will block until it's available. "lock" is recursive, so multiple calls to "lock" are safe--the variable will remain locked until the outermost lock on the variable goes out of scope. Locks on variables only affect "lock" calls--they do not affect normal access to a variable. (Locks on subs are different, and covered in a bit.) If you really, really want locks to block access, then go ahead and tie them to something and manage this yourself. This is done on purpose. While managing access to variables is a good thing, Perl doesn't force you out of its living room... If a container object, such as a hash or array, is locked, all the elements of that container are not locked. For example, if a thread does a "lock @a", any other thread doing a "lock($a[12])" won't block. Finally, "lock" will traverse up references exactly one level. "lock($a)" is equivalent to "lock($a)", while "lock(\$a)" is not. async BLOCK; "async" creates a thread to execute the block immediately following it. This block is treated as an anonymous sub, and so must have a semi-colon after the closing brace. Like "Thread->new", "async" returns a thread object. Thread->self The "Thread->self" function returns a thread object that represents the thread making the "Thread->self" call. Thread->list Returns a list of all non-joined, non-detached Thread objects. cond_wait VARIABLE The "cond_wait" function takes a locked variable as a parameter, unlocks the variable, and blocks until another thread does a "cond_signal" or "cond_broadcast" for that same locked variable. The variable that "cond_wait" blocked on is relocked after the "cond_wait" is satisfied. If there are multiple threads "cond_wait"ing on the same variable, all but one will reblock waiting to reaquire the lock on the variable. (So if you're only using "cond_wait" for synchronization, give up the lock as soon as possible.) cond_signal VARIABLE The "cond_signal" function takes a locked variable as a parameter and unblocks one thread that's "cond_wait"ing on that variable. If more than one thread is blocked in a "cond_wait" on that variable, only one (and which one is indeterminate) will be unblocked. If there are no threads blocked in a "cond_wait" on the variable, the signal is discarded. cond_broadcast VARIABLE The "cond_broadcast" function works similarly to "cond_signal". "cond_broadcast", though, will unblock all the threads that are blocked in a "cond_wait" on the locked variable, rather than only one. yield The "yield" function allows another thread to take control of the CPU. The exact results are implementation-dependent. METHODS
join "join" waits for a thread to end and returns any values the thread exited with. "join" will block until the thread has ended, though it won't block if the thread has already terminated. If the thread being "join"ed "die"d, the error it died with will be returned at this time. If you don't want the thread performing the "join" to die as well, you should either wrap the "join" in an "eval" or use the "eval" thread method instead of "join". detach "detach" tells a thread that it is never going to be joined i.e. that all traces of its existence can be removed once it stops running. Errors in detached threads will not be visible anywhere - if you want to catch them, you should use $SIG{__DIE__} or something like that. equal "equal" tests whether two thread objects represent the same thread and returns true if they do. tid The "tid" method returns the tid of a thread. The tid is a monotonically increasing integer assigned when a thread is created. The main thread of a program will have a tid of zero, while subsequent threads will have tids assigned starting with one. done The "done" method returns true if the thread you're checking has finished, and false otherwise. DEFUNCT
The following were implemented with 5005threads, but are no longer available with ithreads. lock(&sub) With 5005threads, you could also "lock" a sub such that any calls to that sub from another thread would block until the lock was released. Also, subroutines could be declared with the ":locked" attribute which would serialize access to the subroutine, but allowed different threads non-simultaneous access. eval The "eval" method wrapped an "eval" around a "join", and so waited for a thread to exit, passing along any values the thread might have returned and placing any errors into $@. flags The "flags" method returned the flags for the thread - an integer value corresponding to the internal flags for the thread. SEE ALSO
threads, threads::shared, Thread::Queue, Thread::Semaphore perl v5.12.1 2010-04-26 Thread(3pm)
All times are GMT -4. The time now is 02:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy