Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Pthreads library problem


    I am trying to create a mutual exclusion section between 2 threads, and I use a signal to get one thread to wait for the other, so that it doesn't keep the processor busy checking whether the other thread has unlocked or not yet,

    one thread has:
    errCode = pthread_mutex_lock (mut);
    /* do mutex work*/
    errCode = pthread_mutex_unlock(mut);
    errCode = pthread_cond_signal (mySig);

    The other has:
    errCode = pthread_mutex_lock (mut);
    errCode = pthread_cond_wait (mySig);
    /* do mutex work*/
    errCode = pthread_mutex_unlock (mut);

    I have a dead lock, I am using default initialization for the mutex declaring it as a pointer as follows:
    mut = (pthread_mutex_t *) malloc (sizeof (pthread_mutex_t));
    pthread_mutex_init (mut, NULL);

    However, I don't know if it is Recursuve, fast or error checking mutex, so I thought I can use the following declartion:


    but I can't use the constants of the pthread library, and the error codes as well, although I am including the pthreads.h header file, other constants I can't use: EINVAL, EDEADLK, EBUSY, EPERM, ... etc

    I appreciate any help, thank you for your time in advance,


  2. #2
    if we set the attribute to null it by default takes fast as the attribute .

    ya to remove the deadlock and to set the attributes to recursive one
    just use

    hope it works!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts