hg05_race2.vgtest \
hg06_readshared.stderr.exp \
hg06_readshared.vgtest \
+ hold_lock_1.stderr.exp \
+ hold_lock_1.vgtest \
+ hold_lock_2.stderr.exp \
+ hold_lock_2.vgtest \
linuxthreads_det.stderr.exp \
linuxthreads_det.stderr.exp-linuxthreads \
linuxthreads_det.stdout.exp \
hg04_race \
hg05_race2 \
hg06_readshared \
+ hold_lock \
linuxthreads_det \
matinv \
memory_allocation \
hg06_readshared_SOURCES = ../../helgrind/tests/hg06_readshared.c
hg06_readshared_LDADD = -lpthread
+hold_lock_SOURCES = hold_lock.c
+hold_lock_LDADD = -lpthread
+
linuxthreads_det_SOURCES = linuxthreads_det.c
linuxthreads_det_LDADD = -lpthread
--- /dev/null
+/** Hold several types of synchronization objects locked as long as specified.
+ */
+
+#define _GNU_SOURCE 1
+
+#include <assert.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+
+static void delay_ms(const int ms)
+{
+ struct timespec ts;
+
+ assert(ms >= 0);
+ ts.tv_sec = ms / 1000;
+ ts.tv_nsec = (ms % 1000) * 1000 * 1000;
+ nanosleep(&ts, 0);
+}
+
+int main(int argc, char** argv)
+{
+ int interval = 0;
+ int optchar;
+ pthread_mutex_t mutex;
+ pthread_mutexattr_t mutexattr;
+ pthread_rwlock_t rwlock;
+
+ while ((optchar = getopt(argc, argv, "i:")) != EOF)
+ {
+ switch (optchar)
+ {
+ case 'i':
+ interval = atoi(optarg);
+ break;
+ default:
+ fprintf(stderr, "Usage: %s [-i <interval time in ms>].\n", argv[0]);
+ break;
+ }
+ }
+
+ fprintf(stderr, "Locking mutex ...\n");
+
+ pthread_mutexattr_init(&mutexattr);
+ pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init(&mutex, &mutexattr);
+ pthread_mutexattr_destroy(&mutexattr);
+ pthread_mutex_lock(&mutex);
+ delay_ms(interval);
+ pthread_mutex_lock(&mutex);
+ pthread_mutex_unlock(&mutex);
+ pthread_mutex_unlock(&mutex);
+ pthread_mutex_destroy(&mutex);
+
+ fprintf(stderr, "Locking rwlock exclusively ...\n");
+
+ pthread_rwlock_init(&rwlock, 0);
+ pthread_rwlock_wrlock(&rwlock);
+ delay_ms(interval);
+ pthread_rwlock_unlock(&rwlock);
+ pthread_rwlock_destroy(&rwlock);
+
+ fprintf(stderr, "Locking rwlock shared ...\n");
+
+ pthread_rwlock_init(&rwlock, 0);
+ pthread_rwlock_rdlock(&rwlock);
+ delay_ms(interval);
+ pthread_rwlock_rdlock(&rwlock);
+ pthread_rwlock_unlock(&rwlock);
+ pthread_rwlock_unlock(&rwlock);
+ pthread_rwlock_destroy(&rwlock);
+
+ fprintf(stderr, "Done.\n");
+
+ return 0;
+}
--- /dev/null
+
+Locking mutex ...
+Acquired at:
+ at 0x........: pthread_mutex_lock (drd_pthread_intercepts.c:?)
+ by 0x........: main (hold_lock.c:?)
+Lock on mutex 0x........ was held during ... ms (threshold: 500 ms).
+ at 0x........: pthread_mutex_unlock (drd_pthread_intercepts.c:?)
+ by 0x........: main (hold_lock.c:?)
+Locking rwlock exclusively ...
+
+Acquired at:
+ at 0x........: pthread_rwlock_wrlock* (drd_pthread_intercepts.c:?)
+ by 0x........: main (hold_lock.c:?)
+Lock on rwlock 0x........ was held during ... ms (threshold: 500 ms).
+ at 0x........: pthread_rwlock_unlock* (drd_pthread_intercepts.c:?)
+ by 0x........: main (hold_lock.c:?)
+Locking rwlock shared ...
+Done.
+
+ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
--- /dev/null
+
+Locking mutex ...
+Locking rwlock exclusively ...
+Locking rwlock shared ...
+Acquired at:
+ at 0x........: pthread_rwlock_rdlock* (drd_pthread_intercepts.c:?)
+ by 0x........: main (hold_lock.c:?)
+Lock on rwlock 0x........ was held during ... ms (threshold: 500 ms).
+ at 0x........: pthread_rwlock_unlock* (drd_pthread_intercepts.c:?)
+ by 0x........: main (hold_lock.c:?)
+Done.
+
+ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)