pthreads c programming

Associate
Joined
28 Apr 2003
Posts
492
Hi, not sure what response I will get here but I'm doing some programming on w32 using cygwin (I know this is linux forum but cygwin, gcc and pthreads seem more applicable here)

I'm trying to get pthreads to use both cores on my system but the code I have uses no more then if I just run the same proccess in a single thread.

Task manager shows 25% on both cores, can't get it to go any higher.

Code im using to initiate the threads are as follows,

pthread_t thread1, thread2;
char *message1 = "Thread 1 finished";
char *message2 = "Thread 2 finished";
int iret1, iret2;

//start thread(s)
iret1 = pthread_create( &thread1, NULL, myfunction_t1, (void*) message1);
iret2 = pthread_create( &thread2, NULL, myfunction_t2, (void*) message2);



//implement second thread divide work properly
pthread_join( thread1, NULL);
pthread_join( thread2, NULL);

As far as I'm aware that should be it, if I get both functions to blot output to screen I see output from each function one after another but I can't get it to use all my cpu power.

Any advice?
 
I'd imagine this is a limitation of cygwin, more than anything else. Does the code compile and execute as expected on another multi-CPU environment e.g. a SMP-kernel linux install?

The following also makes interesting reading and may explain why you are encountering this problem:

http://cygwin.com/cygwin-ug-net/highlights.html#ov-hi-process

Also would it be too bold to ask, if performance is an issue why you are compiling and running code under what is essentially an emulated environment? Just a question :)
 
Thanks for the link.

Main reason I'm using cygwin is it's free, and I like my code to be portable.

I'll try it on my linux box tonight. Bit of pain booting in to it at moment as can't get my raid partition (where the boot partition is) to load in linux so have to change disk prioritys in bios.
 
Back
Top Bottom