I don't understand. I am confused about it.

Source: Internet
Author: User
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;

}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.