#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
char password[ ] = "password" ;
char str[ 30 ] ;
pthread_cond_t wake_up;
pthread_mutex_t mut;
void * enter_pass( )
{
while ( 1 )
{
pthread_cond_signal( & wake_up) ;
pthread_cond_wait( & wake_up, & mut) ;
}
}
void * check_pass( )
{
while ( 1 ) {
pthread_cond_wait( & wake_up, & mut) ;
}
else
printf ( "Wrong password, try another\n " ) ; pthread_cond_signal( & wake_up) ;
}
}
int main( void )
{
pthread_t thread1, thread2;
int rc;
rc = pthread_create( & thread1, NULL, enter_pass, NULL) ;
if ( rc) {
//exit(EXIT_FAILURE);
}
rc = pthread_create( & thread2, NULL, check_pass, NULL) ;
if ( rc) {
//exit(EXIT_FAILURE);
}
}
I2luY2x1ZGUgPHB0aHJlYWQuaD4KI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPGVycm5vLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCmNoYXIgcGFzc3dvcmRbXSA9ICJwYXNzd29yZCI7CmNoYXIgc3RyWzMwXTsKCnB0aHJlYWRfY29uZF90IHdha2VfdXA7CnB0aHJlYWRfbXV0ZXhfdCBtdXQ7CnZvaWQgKmVudGVyX3Bhc3MoKQp7Cgl3aGlsZSgxKQoJewoJCXByaW50ZigiRW50ZXIgcGFzc3dvcmQ6XG4iKTsKCQlzY2FuZigiJXMiLCBzdHIpOwoJCXB0aHJlYWRfY29uZF9zaWduYWwoJndha2VfdXApOwoJCXB0aHJlYWRfY29uZF93YWl0KCZ3YWtlX3VwLCAmbXV0KTsKCX0KfQoKdm9pZCAqY2hlY2tfcGFzcygpCnsKCXdoaWxlKDEpIHsKCQlwdGhyZWFkX2NvbmRfd2FpdCgmd2FrZV91cCwgJm11dCk7CgkJaWYoIXN0cmNtcChzdHIgLCBwYXNzd29yZCkpIHsKCQkJCXByaW50ZigidHJ1ZVxuIik7CgkJCQlle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