[Lldb-commits] [lldb] r205900 - Do not rely on invalid pthread API use in thread test
Ed Maste
emaste at freebsd.org
Wed Apr 9 07:48:26 PDT 2014
Author: emaste
Date: Wed Apr 9 09:48:25 2014
New Revision: 205900
URL: http://llvm.org/viewvc/llvm-project?rev=205900&view=rev
Log:
Do not rely on invalid pthread API use in thread test
Calling mutex_lock from one thread and then mutex_unlock from another is
not permitted. Replace the awkward mutex usage with a mutex and
condition variable.
llvm.org/pr18061
Modified:
lldb/trunk/test/functionalities/thread/TestNumThreads.py
lldb/trunk/test/functionalities/thread/main.c
Modified: lldb/trunk/test/functionalities/thread/TestNumThreads.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/thread/TestNumThreads.py?rev=205900&r1=205899&r2=205900&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/thread/TestNumThreads.py (original)
+++ lldb/trunk/test/functionalities/thread/TestNumThreads.py Wed Apr 9 09:48:25 2014
@@ -19,7 +19,6 @@ class NumberOfThreadsTestCase(TestBase):
self.buildDsym()
self.number_of_threads_test()
- @expectedFailureFreeBSD("llvm.org/pr18061") # test relies on undefined behaviour
@dwarf_test
def test_with_dwarf(self):
"""Test number of threads."""
Modified: lldb/trunk/test/functionalities/thread/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/thread/main.c?rev=205900&r1=205899&r2=205900&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/thread/main.c (original)
+++ lldb/trunk/test/functionalities/thread/main.c Wed Apr 9 09:48:25 2014
@@ -1,24 +1,24 @@
#include <pthread.h>
-pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t mutex3 = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
void *
thread3 (void *input)
{
- pthread_mutex_unlock(&mutex2); // Set break point at this line.
- pthread_mutex_unlock(&mutex1);
+ pthread_mutex_lock(&mutex);
+ pthread_cond_signal(&cond); // Set break point at this line.
+ pthread_mutex_unlock(&mutex);
return NULL;
}
void *
thread2 (void *input)
{
- pthread_mutex_unlock(&mutex3);
- pthread_mutex_lock(&mutex2);
- pthread_mutex_unlock(&mutex2);
-
+ pthread_mutex_lock(&mutex);
+ pthread_cond_signal(&cond);
+ pthread_cond_wait(&cond, &mutex);
+ pthread_mutex_unlock(&mutex);
return NULL;
}
@@ -28,9 +28,6 @@ thread1 (void *input)
pthread_t thread_2;
pthread_create (&thread_2, NULL, thread2, NULL);
- pthread_mutex_lock(&mutex1);
- pthread_mutex_unlock(&mutex1);
-
pthread_join(thread_2, NULL);
return NULL;
@@ -38,21 +35,23 @@ thread1 (void *input)
int main ()
{
- pthread_t thread_1;
- pthread_t thread_3;
+ pthread_t thread_1;
+ pthread_t thread_3;
+
+ pthread_mutex_lock (&mutex);
+
+ pthread_create (&thread_1, NULL, thread1, NULL);
- pthread_mutex_lock (&mutex1);
- pthread_mutex_lock (&mutex2);
- pthread_mutex_lock (&mutex3);
+ pthread_cond_wait (&cond, &mutex);
- pthread_create (&thread_1, NULL, thread1, NULL);
+ pthread_create (&thread_3, NULL, thread3, NULL);
- pthread_mutex_lock(&mutex3);
- pthread_create (&thread_3, NULL, thread3, NULL);
+ pthread_cond_wait (&cond, &mutex);
- pthread_join (thread_1, NULL);
- pthread_join (thread_3, NULL);
+ pthread_mutex_unlock (&mutex);
- return 0;
+ pthread_join (thread_1, NULL);
+ pthread_join (thread_3, NULL);
+ return 0;
}
More information about the lldb-commits
mailing list