943,994 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4051
  • C RSS
Oct 22nd, 2004
0

PThreads: question on basic problem (or POSIX Threads)

Expand Post »
ok, I have an assignment ...

it requires the use of pthreads ..

i pretty much understand it, well, sorta ....

the assignment is to read input from the command line (input redirection) from a file

the file contains a list of numbers, 1 per line, 50 total numbers max

we are then going to sort the numbers using the Odd-Even Transposition Sorting Algorithm.

so for each number we compare and sort, we are to use pthreads for each set of 2 numbers ...

anyone familiar with the sorting algorithm?

if not, let me know, and ill explain, but otherwise, ill default to the guess that you guys do ...

anyways ....

my question is, with pthreads, you have to create a PThread ID for each pthread call, right?

example:

  1. main()
  2. {
  3. pthread_t thread1, thread2;
  4. char *message1 = "Thread 1";
  5. char *message2 = "Thread 2";
  6. int iret1, iret2;
  7.  
  8. /* Create independant threads each of which will execute function */
  9.  
  10. pthread_create( &thread1, NULL, print_message_function, (void*) message1);
  11. pthread_create( &thread2, NULL, print_message_function, (void*) message2);
  12. .
  13. .
  14. .
  15. .
  16. .

we declared 2 pthread ID's, "thread1" and "thread2"

this allowed me to create 2 different threads?

but in my assignment, we dont know how many threads we will be creating until we read in all the numbers ....

so im not sure how to declare all the pthread ID's I will need to declare?

any help/point-in-right-direction would be great .....
Similar Threads
Reputation Points: 12
Solved Threads: 0
Light Poster
jaeSun is offline Offline
31 posts
since Oct 2004

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 C Forum Timeline: C Language
Next Thread in C Forum Timeline: Array without twice the same number?





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


Follow us on Twitter


© 2011 DaniWeb® LLC