kosta has asked for the wisdom of the Perl Monks concerning the following question:
I have a question about threads. Lets say we have a very trivial thread example:
#!/usr/bin/perl use threads; use strict; my $thr = threads->new(\&sub1); sub sub1 { print "hi from thread"; }
Now is there a way for me to control thread $thr from within sub1? Especially since I want to send $thr as an argument to another function from sub1. So I need the full scalar reference to thread object $thr. I basically ask if there is any way to get reference to $thr from within sub1?
e.g. to make it work like this
my $thr = threads->new(\&sub1); sub sub1 { my $self_thread = $(this); #I know this is absolutely wrong ju +st trying to make you understand what I want print "hi from thread $self_thread"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing Thread within its run
by BrowserUk (Patriarch) on Feb 15, 2012 at 20:03 UTC | |
by kosta (Sexton) on Feb 15, 2012 at 20:19 UTC |