File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ #include < thread>
3+
4+ #include " test.h"
5+
6+ #ifdef __linux__
7+ #include < pthread.h>
8+ #include < time.h>
9+
10+ TEST (PThread, Robust) {
11+ pthread_mutexattr_t ma;
12+ pthread_mutexattr_init (&ma);
13+ pthread_mutexattr_setrobust (&ma, PTHREAD_MUTEX_ROBUST);
14+ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
15+ pthread_mutex_init (&mutex, &ma);
16+
17+ std::thread{[&mutex] {
18+ pthread_mutex_lock (&mutex);
19+ // pthread_mutex_unlock(&mutex);
20+ }}.join ();
21+
22+ struct timespec tout;
23+ clock_gettime (CLOCK_REALTIME, &tout);
24+ struct tm *tmp = localtime (&tout.tv_sec );
25+ tout.tv_sec += 1 ; /* 1 seconds from now */
26+ int r = pthread_mutex_timedlock (&mutex, &tout);
27+ EXPECT_EQ (r, EOWNERDEAD);
28+
29+ pthread_mutex_consistent (&mutex);
30+ pthread_mutex_unlock (&mutex);
31+ pthread_mutex_destroy (&mutex);
32+ }
33+ #endif // __linux__
You can’t perform that action at this time.
0 commit comments