58 lines
976 B
C++
58 lines
976 B
C++
/*
|
|
das ist ein test für gitea
|
|
*/
|
|
#include <pthread.h>
|
|
#include <unistd.h>
|
|
#include <iostream>
|
|
|
|
void* threadFunction1( void* );
|
|
void* threadFunction2( void* );
|
|
|
|
int state = 0;
|
|
pthread_cond_t condvar;
|
|
pthread_mutex_t mutex;
|
|
|
|
|
|
int main()
|
|
{
|
|
pthread_t t1, t2;
|
|
pthread_mutex_init( &mutex, 0 );
|
|
pthread_cond_init( &condvar, 0 );
|
|
pthread_create( &t1, 0, threadFunction1, 0 );
|
|
pthread_create( &t2, 0, threadFunction2, 0 );
|
|
|
|
pthread_join( t1, 0 );
|
|
pthread_join( t2, 0 );
|
|
pthread_mutex_destroy( &mutex );
|
|
pthread_cond_destroy( &condvar );
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
void* threadFunction1( void* )
|
|
{
|
|
pthread_mutex_lock( &mutex );
|
|
std::cout << "ding" << std::endl;
|
|
state = 1;
|
|
pthread_cond_signal( &condvar );
|
|
pthread_mutex_unlock( &mutex );
|
|
|
|
return 0;
|
|
}
|
|
|
|
void* threadFunction2( void* )
|
|
{
|
|
pthread_mutex_lock( &mutex );
|
|
while( state != 1 )
|
|
{
|
|
pthread_cond_wait( &condvar, &mutex );
|
|
}
|
|
sleep( 1 );
|
|
std::cout << "dong" << std::endl;
|
|
pthread_mutex_unlock( &mutex );
|
|
|
|
return 0;
|
|
}
|
|
|