943,186 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 5297
  • Perl RSS
Sep 15th, 2005
0

Problem passing variables to thread

Expand Post »
I'm having difficulty passing variables to threads. I've recently compiled 5.8.7 with threads enabled and I am using the new ithreads. When running code as follows:

use Thread qw(async);

async {
while(1) {
print 1;
}
};

while (1) {
print 2;
}

The code works as expected and prints both 1's and 2's. But whenever I try to use a parent's variables in children processes I run into problems. For example from the camel book:

use Thread qw(async);
use Thread::Queue;

my $Q = Thread::Queue->new();
async {
while (defined($datum = $Q->dequeue)) {
print $datum;
}
};

$Q->enqueue(12);
$Q->enqueue("A");

while(1) {
print 1;
}

12 and A are never printed, just 1; And if I try printing $Q from both inside and outside the async block, they reference to different objects. I was under the impression, and I believe the O'Reilly book is to, that children have direct access to var
iables that are created in the parents before the thread is initiated. Am I wrong in this assumption? Is there a compiler flag that I missed to allow this kind of variable scope? If this code is wrong any insights on how to access parent process objects from within threads would be greatly appreciated.

I'm using linux (kernel 2.6.11). I'm not sure what other information about my system configuration could pertain to this problem. Please ask if more info is needed.

Thanks in advance for any help given.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
barteled is offline Offline
1 posts
since Sep 2005
Aug 6th, 2008
0

Re: Problem passing variables to thread

Yep, there is a limit to the amount of GET data. If my memeory servers my well, it's 255 bytes (characters). I'm not sure if this is before or after url encoding.

With that amount of data, I suggest going either to a form with POST data, or writing some of if off to a session.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Lamer980 is offline Offline
3 posts
since Aug 2008
Aug 6th, 2008
0

Re: Problem passing variables to thread

Click to Expand / Collapse  Quote originally posted by Lamer980 ...
Yep, there is a limit to the amount of GET data. If my memeory servers my well, it's 255 bytes (characters). I'm not sure if this is before or after url encoding.

With that amount of data, I suggest going either to a form with POST data, or writing some of if off to a session.
I think you posted in the wrong thread.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: Subroutine Access
Next Thread in Perl Forum Timeline: No Email::Valid on Mac?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC