fork download
  1. #include <pthread.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <errno.h>
  5. #include <string.h>
  6.  
  7. char password[] = "password";
  8. char str[30];
  9.  
  10. pthread_cond_t wake_up;
  11. pthread_mutex_t mut;
  12. void *enter_pass()
  13. {
  14. while(1)
  15. {
  16. printf("Enter password:\n");
  17. scanf("%s", str);
  18. pthread_cond_signal(&wake_up);
  19. pthread_cond_wait(&wake_up, &mut);
  20. }
  21. }
  22.  
  23. void *check_pass()
  24. {
  25. while(1) {
  26. pthread_cond_wait(&wake_up, &mut);
  27. if(!strcmp(str , password)) {
  28. printf("true\n");
  29. exit(EXIT_SUCCESS);
  30. }
  31. else
  32. printf("Wrong password, try another\n");
  33. pthread_cond_signal(&wake_up);
  34. }
  35. }
  36.  
  37. int main(void)
  38. {
  39. pthread_t thread1, thread2;
  40. int rc;
  41.  
  42. rc = pthread_create(&thread1, NULL, enter_pass, NULL);
  43. if (rc) {
  44. printf("ERROR: %s\n", strerror(errno));
  45. //exit(EXIT_FAILURE);
  46. }
  47. rc = pthread_create(&thread2, NULL, check_pass, NULL);
  48. if (rc) {
  49. printf("ERROR: %s\n", strerror(errno));
  50. //exit(EXIT_FAILURE);
  51. }
  52. }
  53.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'main':
prog.c:52:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
/home/aCC9x6/ccqdfOzB.o: In function `main':
prog.c:(.text.startup+0x1f): undefined reference to `pthread_create'
prog.c:(.text.startup+0x38): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty