]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
All newlines are borked -- fix.
authorNicholas Nethercote <n.nethercote@gmail.com>
Mon, 13 Sep 2004 20:51:10 +0000 (20:51 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Mon, 13 Sep 2004 20:51:10 +0000 (20:51 +0000)
MERGED FROM HEAD

git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_2_2_0_BRANCH@2718

helgrind/tests/deadlock.c

index 81da0b4c29f9251616cf87f9919f0897b9039f55..1142f5cfe9a025dbcf7de2e31635704e06bb9b65 100644 (file)
@@ -1 +1,43 @@
-/* Simple possible deadlock */\r#include <pthread.h>\r\rstatic pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER;\rstatic pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER;\r\rstatic void *t1(void *v)\r{\r        pthread_mutex_lock(&m1);\r       pthread_mutex_lock(&m2);\r       pthread_mutex_unlock(&m1);\r     pthread_mutex_unlock(&m2);\r\r    return 0;\r}\r\rstatic void *t2(void *v)\r{\r        pthread_mutex_lock(&m2);\r       pthread_mutex_lock(&m1);\r       pthread_mutex_unlock(&m1);\r     pthread_mutex_unlock(&m2);\r\r    return 0;\r}\r\rint main()\r{\r      pthread_t a, b;\r        \r       /* prevent spurious messages from the dynamic linker */\r        pthread_mutex_lock(&m1);\r       pthread_mutex_unlock(&m1);\r\r    pthread_create(&a, NULL, t1, NULL);     \r       pthread_create(&b, NULL, t2, NULL);\r\r   pthread_join(a, NULL);\r pthread_join(b, NULL);\r\r        return 0;\r}\r
\ No newline at end of file
+/* Simple possible deadlock */
+#include <pthread.h>
+
+static pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER;
+
+static void *t1(void *v)
+{
+       pthread_mutex_lock(&m1);
+       pthread_mutex_lock(&m2);
+       pthread_mutex_unlock(&m1);
+       pthread_mutex_unlock(&m2);
+
+       return 0;
+}
+
+static void *t2(void *v)
+{
+       pthread_mutex_lock(&m2);
+       pthread_mutex_lock(&m1);
+       pthread_mutex_unlock(&m1);
+       pthread_mutex_unlock(&m2);
+
+       return 0;
+}
+
+int main()
+{
+       pthread_t a, b;
+       
+       /* prevent spurious messages from the dynamic linker */
+       pthread_mutex_lock(&m1);
+       pthread_mutex_unlock(&m1);
+
+       pthread_create(&a, NULL, t1, NULL);     
+       pthread_create(&b, NULL, t2, NULL);
+
+       pthread_join(a, NULL);
+       pthread_join(b, NULL);
+
+       return 0;
+}
+