Hello Ukhas,

When you create a thread, your main thread continues, so effectively you 
have 2 threads running. The problem once your main thread creates a new 
thread, it reaches the end of the application code, so it terminates. 
When it terminates, all other threads are killed as well. That's why you 
have the error message.

Of course, you cannot be sure when the new thread starts, so not seeing 
the print statement in the new thread does not mean that the new thread 
has not started. The way to do it may be to sleep() the main thread for 
maybe 2-3 seconds. You should see the print statement.

ukhas jean wrote:
> Hello All,
>  
> Well the query i am about to ask may seem amatuerish, but i am asking 
> it newayz...
> hope u gurus might not mind me asking such a thing ....
>  
> I had the following code :-  
> use threads;
> $thr = threads->new(\&sub1);
> sub sub1
> {
>  print "Inside the thread\n ";
> }
>  
> O/p comes:-
> A thread exited while 2 other threads were still running.
> I am using Perl 5.8.0 on Win XP.
> Plz note:- The content in the subroutine is not printed. I read it 
> somewhere that we need to pass the reference of the subroutine to the 
> new() method. But on doing so, the print statement in the subroutine 
> is not getting executed.
>  
> So i removed the reference and made the statement as:-
> $thr = threads->new(&sub1);
>  
> O/p comes:-
> Inside the thread
> A thread exited while 2 other threads were still running.
> Here the print statement inside the subroutine sub1 gets executed. 
> Which of these is the correct syntax??
> But here I am not passing the reference of the subroutine ... Can any 
> of u masters help me understand this?? Sorry, if the query is a stupid 
> one, but i really can't make sense of it.
> Even if someone canguide/advise me to look at any documentation i shld 
> refer to ... would be great help ...
>  
> Hoping u will kindly oblige ...
>  
> Thanks and Regards,
> Ukhas Jean.  
>
> ------------------------------------------------------------------------
> Do you Yahoo!?
> Next-gen email? Have it all with the all-new Yahoo! Mail Beta. 
> <http://us.rd.yahoo.com/evt=40791/*http://advision.webevents.yahoo.com/handraisers>
>  
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ActivePerl mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to