thread pool problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers thread pool problem
# 1  
Old 12-21-2010
thread pool problem

hello everyone. I want to implement a thread pool, with 10 threads most. Inside main,I call a function (lets say it foo) wich creates (if it is needed) or uses an existing thread from the pool and sends it to do a job.My problem is that I dont know how to pass the argument from the main to the thread which will do the job. But when foo is creating or use a thread to do the job, passes to the thread the pool as an argument. But I want to pass also an other argument from main. So,in the case where foo creates a new thread and send it to do the job, I want to pass an other argument except from pool.But pthread_creat has only 1 argument.Also,in case foo uses an existing thread and wakes it up to do the job,how will foo can pass to that thread the argument??? I have already written most of the code for the pool,and this is one of the few things left,please help! thanks in advance
# 2  
Old 12-21-2010
pthread_create has a void* argument for passing values.
create a struct that has as many arguments as you want, pass that.
Code:
typedef struct
{
   char string[64];
   double  dbl;
   int  intarg;
} my args_t;
// ...............
args_t myargs;
pthread_t tid;
myargs.dbl=32.3;
strcpy(myargs, "some string value");
myargs.intarg=42;
pthread_create(&tid, foo, NULL< &myargs);

in function foo()
Code:
foo(void *args)
{
     myargs_t *arg=(myargs_t *) args;
     printf("%d\n", arg->intarg); 
}

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 12-21-2010
Great,Thanks a lot! although so obvious i couldnt see it!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

I am still meet a problem when I want to reply or create a new thread

Hi, Scott, I am still meet a problem when I want to reply or create a new thread in "Shell Programming and Scripting" Forum, It reminds that: To create new threads in this forum your post count must be 10 or greater. You currently have 2 posts. To my surprise, I posted a thread in "Shell... (4 Replies)
Discussion started by: weichanghe2000
4 Replies

2. Programming

Multi thread data sharing problem in uclinux

hello, I have wrote a multi thread application to run under uclinux. the problem is that threads does not share data. using the ps command it shows a single process for each thread. I test the application under Ubuntu 8.04 and Open Suse 10.3 with 2.6 kernel and there were no problems and also... (8 Replies)
Discussion started by: mrhosseini
8 Replies

3. Solaris

Problem with pool Service

hi all, i am trying to enable pool service but i recive this message -bash-3.00# pooladm pooladm: couldn't open pools state file: Facility is not active -bash-3.00# pooladm -e svcadm: Instance "svc:/system/pools:default" is in maintenance state. pooladm: cannot enable pools:... (4 Replies)
Discussion started by: corvinusbsd
4 Replies

4. Infrastructure Monitoring

zfs - migrate from pool to pool

Here are the details. cnjr-opennms>root$ zfs list NAME USED AVAIL REFER MOUNTPOINT openpool 20.6G 46.3G 35.5K /openpool openpool/ROOT 15.4G 46.3G 18K legacy openpool/ROOT/rds 15.4G 46.3G 15.3G / openpool/ROOT/rds/var 102M ... (3 Replies)
Discussion started by: pupp
3 Replies

5. Post Here to Contact Site Administrators and Moderators

posting thread is problem

hi, i am unable to post new thread. pls revert back what i need to do. i already posted 3 threads.... I am getting message like " Message is too short" even though my message is more than 100 characters. (1 Reply)
Discussion started by: spc432
1 Replies

6. AIX

HMC & Processor Pool problem

Hi, I am having problem allocating all my processors -- 6 processors -- to sharedpool1 I have 6 processors and I want my lpars to share all these 6 processors. DefaultPool can't be edited. I edit my Sharedpool1 as follows Reserved:0 Max Processors: 6 In my lpar profile: Min: 1... (1 Reply)
Discussion started by: filosophizer
1 Replies

7. UNIX for Advanced & Expert Users

Thread synchronisation problem...

Hello, hope my english will be sufficient to be clear enough... I'm in progress on some script that should copy one big source file (200GB average) on one sata drive, to multiple (30+) sata drives. Hardware is not the problem but copy performance is... If i launch all copy process at the same... (4 Replies)
Discussion started by: Gnaag
4 Replies

8. Programming

Question on creation of Thread pool

dear sir/madam presently i am in a process of creating a multithread pool using clone() system call in unix with c programming. i am facing some problem ie., i am able create multithread pool and able to keep all the threads in wait state,but when i call kill (afunction revoke a... (6 Replies)
Discussion started by: Radha
6 Replies
Login or Register to Ask a Question