fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int cont=0;
  5. void *funzione2(void *ptr)
  6. {
  7. for(;;)
  8. {
  9. pthread_mute_lock(&mutex1);
  10. if((cont<3)||(cont>6))
  11. {
  12. pthread_cond_signal(&condition)
  13. }
  14. else
  15. {
  16. cont++;
  17. printf("funzione2 %d", cont);
  18. }
  19.  
  20. pthread_mutex_unlock(&mutex1);
  21. if(cont>=10)
  22. return NULL;
  23. }
  24. }
  25. void *funzione1(void *ptr)
  26. {
  27. for(;;)
  28. {
  29. pthread_mutex_lock(&mutex1);
  30. pthread_cond_wait(&condition, &mutex);
  31. cont++;
  32.  
  33. printf("funzione1 %d", cont);
  34. pthread_mutex_unlock(&mutex1);
  35. if(cont>=10)
  36. return NULL;
  37. }
  38. }
  39.  
  40. int main() {
  41. // your code goes here
  42. return 0;
  43. pthread_t thread1;
  44. pthread_t thread2;
  45.  
  46. pthread_create(&thread1, NULL, funzione1, NULL);
  47. pthread_create(&thread2, NULL, funzione2, NULL);
  48.  
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:9:22: error: use of undeclared identifier 'mutex1'
                pthread_mute_lock(&mutex1);
                                   ^
prog.cpp:12:35: error: expected ';' after expression
                        pthread_cond_signal(&condition)
                                                       ^
                                                       ;
prog.cpp:12:25: error: use of undeclared identifier 'condition'
                        pthread_cond_signal(&condition)
                                             ^
prog.cpp:20:25: error: use of undeclared identifier 'mutex1'
                pthread_mutex_unlock(&mutex1);
                                      ^
prog.cpp:29:23: error: use of undeclared identifier 'mutex1'
                pthread_mutex_lock(&mutex1);
                                    ^
prog.cpp:30:22: error: use of undeclared identifier 'condition'
                pthread_cond_wait(&condition, &mutex);
                                   ^
prog.cpp:30:34: error: use of undeclared identifier 'mutex'
                pthread_cond_wait(&condition, &mutex);
                                               ^
prog.cpp:34:25: error: use of undeclared identifier 'mutex1'
                pthread_mutex_unlock(&mutex1);
                                      ^
8 errors generated.
stdout
Standard output is empty