mirror of
https://abf.rosa.ru/djam/glibc40.git
synced 2025-02-23 15:52:52 +00:00
95 lines
2.1 KiB
Diff
95 lines
2.1 KiB
Diff
From 2efa9591e5e8a129e7b73ad0dad3eecbd69482ff Mon Sep 17 00:00:00 2001
|
|
From: "Pierre-Loup A. Griffais" <pgriffais@valvesoftware.com>
|
|
Date: Tue, 30 Jul 2019 16:44:27 -0700
|
|
Subject: [PATCH] HACK: test app for pthread_mutex_lock_any(); should be
|
|
tst-mutex* something.
|
|
|
|
---
|
|
multimutextestapp/testapp.c | 78 +++++++++++++++++++++++++++++++++++++
|
|
1 file changed, 78 insertions(+)
|
|
create mode 100644 multimutextestapp/testapp.c
|
|
|
|
diff --git a/multimutextestapp/testapp.c b/multimutextestapp/testapp.c
|
|
new file mode 100644
|
|
index 0000000000..eecf842dbc
|
|
--- /dev/null
|
|
+++ b/multimutextestapp/testapp.c
|
|
@@ -0,0 +1,78 @@
|
|
+#include <errno.h>
|
|
+#include <pthread.h>
|
|
+#include <stdio.h>
|
|
+#include <stdlib.h>
|
|
+#include <unistd.h>
|
|
+
|
|
+
|
|
+static pthread_mutex_t m[3];
|
|
+
|
|
+
|
|
+static void *
|
|
+tf (void *arg)
|
|
+{
|
|
+ int out;
|
|
+ int ret = pthread_mutex_lock_any( m, 3, &out );
|
|
+
|
|
+ printf("new thread ret %i out %i!\n", ret, out );
|
|
+
|
|
+ sleep(5);
|
|
+ printf("new thread done sleeping!\n");
|
|
+
|
|
+ pthread_mutex_unlock( &m[out] );
|
|
+
|
|
+ return NULL;
|
|
+}
|
|
+
|
|
+
|
|
+int main(int ac, char**av)
|
|
+{
|
|
+ pthread_mutex_init (&m[0], NULL);
|
|
+ pthread_mutex_init (&m[1], NULL);
|
|
+ pthread_mutex_init (&m[2], NULL);
|
|
+
|
|
+ int out;
|
|
+
|
|
+ int ret = pthread_mutex_lock_any( m, 3, &out );
|
|
+
|
|
+ printf("main thread ret %i out %i!\n", ret, out );
|
|
+
|
|
+
|
|
+ pthread_t th;
|
|
+ if (pthread_create (&th, NULL, tf, NULL) != 0)
|
|
+ {
|
|
+ puts ("create failed");
|
|
+ return 1;
|
|
+ }
|
|
+
|
|
+ sleep(1);
|
|
+
|
|
+ ret = pthread_mutex_lock_any( m, 3, &out );
|
|
+
|
|
+ printf("main thread ret %i out %i!\n", ret, out );
|
|
+
|
|
+ sleep(1);
|
|
+
|
|
+ struct timespec timeoutTime;
|
|
+ clock_gettime(CLOCK_REALTIME, &timeoutTime);
|
|
+ timeoutTime.tv_sec += 1;
|
|
+
|
|
+ ret = pthread_mutex_timedlock_any( m, 3, &timeoutTime, &out );
|
|
+
|
|
+ printf("main thread ret %i out %i!\n", ret, out );
|
|
+
|
|
+ clock_gettime(CLOCK_REALTIME, &timeoutTime);
|
|
+ timeoutTime.tv_sec += 3;
|
|
+
|
|
+ ret = pthread_mutex_timedlock_any( m, 3, &timeoutTime, &out );
|
|
+
|
|
+ printf("main thread ret %i out %i!\n", ret, out );
|
|
+
|
|
+ pthread_mutex_unlock( &m[out] );
|
|
+ pthread_mutex_unlock( &m[0] );
|
|
+ pthread_mutex_unlock( &m[2] );
|
|
+
|
|
+ printf("DONE unlock!\n");
|
|
+
|
|
+ return 0;
|
|
+}
|