473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Issue with Thread:Que

gpraghuram
1,275 Expert 1GB
Hi,
I am trying to use Perl Thread:Queue module.
I have written this piece of code

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2.  
  3. use Thread;
  4. use Thread::Queue;
  5.  
  6. my (@Que,@ThreadQ);
  7. my $MAX_THREADS    = 1;
  8.  
  9.  
  10. for my $i(0 .. $MAX_THREADS){
  11.     $Que[$i] = Thread::Queue->new();
  12.     push @ThreadQ, threads->new(\&ThreadFun,$i);
  13. }
  14.  
  15. for my $i(0 .. $MAX_THREADS){
  16.     print "Pushing \"THREADVAL:\"$i to thread :$i\n";
  17.     $Que[$i]->enqueue("THREADVAL:" . "$i");
  18. }
  19.  
  20. sleep(20);
  21.  
  22.  
  23. for(@ThreadQ)
  24. {
  25.     $_->join;
  26. }
  27. @ThreadQ = ();
  28.  
  29.  
  30. sub ThreadFun()
  31. {
  32.     my $QId     = $_[0];
  33.     my $IPArgs     = "";
  34.     print "In thread:$QId\n";
  35.     while ($IPArgs = $Que[$QId]->dequeue) 
  36.     #while ($IPArgs = $Que[$QId]->dequeue) 
  37.     {
  38.         if($IPArgs)
  39.         {
  40.             print "In Thread:$QId:$IPArgs\n";
  41.         }
  42.         else
  43.         {
  44.             print "Sleeping in thread:$QId\n";
  45.             sleep(1);
  46.         }
  47.     }
  48. }
When i use the $Que[$QId]->dequeue call the program dont exit and when i use $Que[$QId]->dequeue_nb the program exits.
But real problem is the thread is not able to read any of the enqued data.
can someone help me with this?

Thanks
Raghu
Jan 14 '10 #1
0 1141

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Bart Nessux | last post by:
Howdy, Below is a script that I'm using to try and count the number of HTTP servers within a company's private network. There are 65,536 possible hosts that may have HTTP servers on them. Any...
7
by: mike | last post by:
Hi, I am having difficulty in creating a thread using pthread_create. It seems that pthread_create does not execute 'program', and returns -1; I have checked the API but I am not sure why this...
9
by: Víctor | last post by:
Hello, I'm filling a array of System.Diagnostic.Process by using GetProcesses() method. Due to a retard on this method, I do the call using a function and it passing like a delegate to one...
1
by: Bill | last post by:
Hi all, I've got my self a bug that I am out of ideas on how to fix... A section of my program launches a thread to handle a FIFO work buffer, I make the fifo as a single link list, the head...
15
by: Ciudad Tecnópolis | last post by:
Hola, primero que todo mil disculpas por postear una pregunta no relacionada al tema pero se que será muy útil para todos! Actualmente estoy presentando un desarrollo en .NET para una compañía y...
25
by: JC | last post by:
Hi People, Please I need your help. This code run a thread ok but Not close later. thanks... private void RunServer(int aPortNumber) {
4
by: Eran.Yasso | last post by:
Hi, Is there a way to stop a loop running in a thread using bool? What i mean is: i have two classes. When i click button(classA) on, i starts running s thread(classB) which is located...
3
by: CMorgan | last post by:
Hi everybody, I am experiencing an annoying problem with fork() and execv(). In my program I need to launch the "pppd" from a thread, so, I create a new process with fork and then in the child...
30
by: nathanwb | last post by:
I am in the learning phase of PHP/Mysql thus my question :) I have a login.php page that passes the following values.. $myusername $mypassword. on submit it sends that data to a checklogin.php...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.