fork(1) download
  1. #include <iostream>
  2. #include <thread>
  3. #include <mutex>
  4.  
  5. using namespace std;
  6. std::timed_mutex g_timed_mutex;
  7.  
  8. void thread1()
  9. {
  10. std::unique_lock<std::timed_mutex> t1(g_timed_mutex);
  11. Sleep(3000);
  12. std::cout << "thread1" << std::endl;
  13. }
  14.  
  15. void thread2()
  16. {
  17. std::unique_lock<std::time_mutex> t1(g_timed_mutex,std::chrono::milliseconds(1000));
  18. std::cout << "thread2" << std::endl;
  19. }
  20. int main() {
  21. // your code goes here
  22. std::thread t1(thread1);
  23. Sleep(1000);
  24. std::thread t2(thread2);
  25. t1.join();
  26. t2.join();
  27. return 0;
  28. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/4.9/thread:35:0,
                 from prog.cpp:2:
/usr/include/c++/4.9/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^
prog.cpp:6:6: error: 'timed_mutex' in namespace 'std' does not name a type
 std::timed_mutex g_timed_mutex;
      ^
prog.cpp: In function 'void thread1()':
prog.cpp:10:2: error: 'unique_lock' is not a member of 'std'
  std::unique_lock<std::timed_mutex> t1(g_timed_mutex);
  ^
prog.cpp:10:19: error: 'timed_mutex' is not a member of 'std'
  std::unique_lock<std::timed_mutex> t1(g_timed_mutex);
                   ^
prog.cpp:10:40: error: 'g_timed_mutex' was not declared in this scope
  std::unique_lock<std::timed_mutex> t1(g_timed_mutex);
                                        ^
prog.cpp:10:53: error: 't1' was not declared in this scope
  std::unique_lock<std::timed_mutex> t1(g_timed_mutex);
                                                     ^
prog.cpp:11:12: error: 'Sleep' was not declared in this scope
  Sleep(3000);
            ^
prog.cpp: In function 'void thread2()':
prog.cpp:17:2: error: 'unique_lock' is not a member of 'std'
  std::unique_lock<std::time_mutex> t1(g_timed_mutex,std::chrono::milliseconds(1000));
  ^
prog.cpp:17:19: error: 'time_mutex' is not a member of 'std'
  std::unique_lock<std::time_mutex> t1(g_timed_mutex,std::chrono::milliseconds(1000));
                   ^
prog.cpp:17:39: error: 'g_timed_mutex' was not declared in this scope
  std::unique_lock<std::time_mutex> t1(g_timed_mutex,std::chrono::milliseconds(1000));
                                       ^
prog.cpp:17:58: error: 'std::chrono' has not been declared
  std::unique_lock<std::time_mutex> t1(g_timed_mutex,std::chrono::milliseconds(1000));
                                                          ^
prog.cpp:17:84: error: 't1' was not declared in this scope
  std::unique_lock<std::time_mutex> t1(g_timed_mutex,std::chrono::milliseconds(1000));
                                                                                    ^
prog.cpp: In function 'int main()':
prog.cpp:22:2: error: 'thread' is not a member of 'std'
  std::thread t1(thread1);
  ^
prog.cpp:23:12: error: 'Sleep' was not declared in this scope
  Sleep(1000);
            ^
prog.cpp:24:2: error: 'thread' is not a member of 'std'
  std::thread t2(thread2);
  ^
prog.cpp:25:2: error: 't1' was not declared in this scope
  t1.join();
  ^
prog.cpp:26:2: error: 't2' was not declared in this scope
  t2.join();
  ^
stdout
Standard output is empty