Computing.Net > Forums > Unix > how do you get pthread to wait for

how do you get pthread to wait for

Reply to Message Icon

Original Message
Name: nace33
Date: September 29, 2004 at 11:29:08 Pacific
Subject: how do you get pthread to wait for
OS: debian
CPU/Ram: p4
Comment:

I am trying to figure out how to have two pthreads interact with one another...I am using mutex to lock the threads out but, the other threads don't stop where they are. How do you get the other threads to suspend or wait for the the thread thats in the critical section. My problem is that i am reading in data from files and i need them read in a certain order...here is my locking code.


//mutex lock
pthread_mutex_lock(&mtx);

//messageWrite(temp2); message.append(temp2);

//mutex unlock pthread_mutex_unlock(&mtx);

i know it is locking out the other process but i need them to stop while the thread is in this area...any help pleeease, very frustrating.


Report Offensive Message For Removal

Response Number 1
Name: fpmurphy
Date: September 29, 2004 at 17:49:32 Pacific
Subject: how do you get pthread to wait for
Reply: (edit)

Its simple - a POSIX thread calling pthread_mutex_lock() to lock the mutex either gets exclusive access to the code starting from the successful locking until its call to unlock the mutex, or it waits until the mutex is unlocked by the thread that locked it.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: how do you get pthread to wait for 

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software