Home > OS >  Pthread_cleanup_pop () error
Pthread_cleanup_pop () error

Time:11-24

#include
#include
using namespace std;

Pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;
Pthread_cond_t cond=PTHREAD_COND_INITIALIZER;
Int a=0;//be mutexes and condition variables, jointly protect data

Void cleanup_handle (void * arg)
{
Pthread_mutex_unlock (& amp; Mutex);
}

Void * route1 (void *)//simulate the function of the operating team: a,
{
Int oldtype;
Int * arg;
Pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, & amp; Oldtype);
Pthread_cleanup_push (cleanup_handle, arg (void *));
Pthread_mutex_lock (& amp; Mutex);
While (a==0)
{
Cout<& lt;" Route1 running "& lt; The pthread_cond_wait (& amp; Cond, & amp; Mutex);
Cout<& lt;" Signal_1 is "& lt; }
A -;
Cout<& lt;" Route1 a is "& lt; Pthread_mutex_unlock (& amp; Mutex);
Pthread_cleanup_pop (0);//second operand to the conditional operator is of type "void", but the third operand is neither a throw - expression nor of type 'void'
//pthread_exit (NULL);

}

Void * route2 (void *)//simulate the operation of the team's function: +
{
Pthread_mutex_lock (& amp; Mutex);
While (a==0)
{
Cout<& lt;" Route2 running "& lt; a++;
Pthread_cond_signal (& amp; Cond);
Cout<& lt;" Signal_2 is "& lt; }
Cout<& lt;" Route2 a is "& lt; Pthread_mutex_unlock (& amp; Mutex);
Pthread_exit (NULL);
}

Int main ()
{
Pthread_t pid1, pid2;

Int status=pthread_create (& amp; Pid1, NULL, route1, NULL);
If (status)
{
Cout<& lt;" Pthread1 create error!" exit(0);
}

Status=pthread_create (& amp; Pid2, NULL, route2, NULL);
If (status)
{
Cout<& lt;" Pthread2 create error!" exit(0);
}
Pthread_join (pid1, NULL);
Pthread_join (pid2, NULL);
return 0;
}
Pthread_cleanup_pop (0) this line error error message above, please, give advice or comments,
  • Related