Tuesday, 15 June 2010

c - Getting wrong value for ID in pthreads -


I'm trying to be my output

  Starting proforma started at Professor 3 But never got me "Professor started 1" when num_professors = 2. I think that creating an array of ID will save the entire passing of the ID, but apparently not. I have about 70 other things for this project and it is quite frustrating to say at least one obstacle on this simple thing (maybe taking a few seconds to decide). Thanks much appreciated 

  Zero * Professorfanks (Zero * P) {sem_wait (and workspace); If (buffer == 0) {buffer ++; Professor * Professor = (Professor *) P; Fprintf (stdout, "initial professor% d \ n", * professor-> ID); } Buffer = 0; Sem_post (& workAssignment); Pthread_exit (0); } Int main (Int arc, four ** argv) {// Semaphore Intelligence buffer = 0; If (sem_init (and task assignment, 0, 1)) {printf ("semaphore could not be started. \ N"); Exit (1); } // thread making pthread_t professor [num_professors]; Professor * P; Int iDes [num_professors]; Int i; P = Mallok (size (* p) * num_professors); For (i = 0; i  ID = & amp; ID [i]; // printf ("id:% d \ n", * p-> ID); If (pthread_create (& professor [i], NULL, professorfank, p)! = 0) {false ("pthread_create"); Exit (1); } // printf ("I'm here after the function \ n"); } For (i = 0; i  

this line:

  if (pthread_create (& Amp; Professor [i], NULL, Professor Funk, P)! = 0) { 

should be:

  if (pthread_create (& amp; Professor) [I], Faucet, Professor Phank, and P [Ii])! = 0) { 

No comments:

Post a Comment