I don't understand. I am confused about the general Linux technology-Linux programming and kernel information. here is the details.
CODE: # include
# Include
# Include
# Include
Pthread_cond_t taxiCond = PTHREAD_COND_INITIALIZER;
Pthread_mutex_t taxiMutex = PTHREAD_MUTEX_INITIALIZER;
Void * traveler_arrive (void * name)
{
Int ret;
Printf ("Traveler % s needs a taxi now1 \ n", name );
Ret = pthread_mutex_lock (& taxiMutex );
If (ret = 0) printf ("cond is locked \ n ");
Pthread_cond_wait (& taxiCond, & taxiMutex );
Printf ("test \ n ");
Pthread_mutex_unlock (& taxiMutex );
Printf ("% s got a taxi \ n", name );
Printf ("traver thread sucess and exit \ n ");
Pthread_exit (void *) 0 );
}
Void * taxi_arrive (void * name)
{
Int ret;
Printf ("taxi % s arrive \ n", name );
Pthread_mutex_unlock (& taxiMutex );
Ret = pthread_cond_signal (& taxiCond );
If (ret = 0) printf ("cond is lived \ n ");
Pthread_mutex_unlock (& taxiMutex );
Printf ("taxi thread sucess and exit \ n ");
Pthread_exit (void *) 0 );
}
Void main ()
{
Pthread_t thread;
Pthread_attr_t threadAttr;
Pthread_attr_init (& threadAttr );
Pthread_create (& thread, & threadAttr, taxi_arrive, (void *) ("Jack "));
Sleep (10 );
Pthread_create (& thread, & threadAttr, traveler_arrive, (void *) ("Susan "));
Sleep (10 );
Pthread_create (& thread, & threadAttr, taxi_arrive, (void *) ("Mike "));
Sleep (10 );
Return;
} |