summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--misc.c2
-rw-r--r--tests/create1.c19
-rw-r--r--tests/equal.c39
-rw-r--r--tests/equal1.c34
5 files changed, 62 insertions, 40 deletions
diff --git a/ChangeLog b/ChangeLog
index 5934633..aa08366 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
1998-10-05 Ben Elliston <bje@cygnus.com>
+ * misc.c (pthread_equal): Correct inverted logic bug.
+
* global.c (PTHREAD_MUTEX_INITIALIZER): Move to pthread.h.
* pthread.h (PTHREAD_MUTEX_INITIALIZER): Define.
@@ -17,6 +19,12 @@
* tests/mutex3.c: New file; test for the static initialisation
macro. Passes.
+
+ * tests/create1.c: New file; test pthread_create(). Passes.
+
+ * tests/equal.c: Poor test; remove.
+
+ * tests/equal1.c New file; test pthread_equal(). Passes.
1998-10-04 Ben Elliston <bje@cygnus.com>
diff --git a/misc.c b/misc.c
index 2408af1..eebebae 100644
--- a/misc.c
+++ b/misc.c
@@ -63,5 +63,5 @@ pthread_self(void)
int
pthread_equal(pthread_t t1, pthread_t t2)
{
- return (t1 != t2);
+ return (t1 == t2);
}
diff --git a/tests/create1.c b/tests/create1.c
new file mode 100644
index 0000000..841c565
--- /dev/null
+++ b/tests/create1.c
@@ -0,0 +1,19 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <windows.h>
+
+void * func(void * arg)
+{
+ printf("Hello world\n");
+ return 0;
+}
+
+int
+main()
+{
+ pthread_t t;
+ pthread_create(&t, NULL, func, NULL);
+
+ Sleep(5000);
+ return 0;
+}
diff --git a/tests/equal.c b/tests/equal.c
deleted file mode 100644
index 12dbfc2..0000000
--- a/tests/equal.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Test for pthread_equal().
- *
- * Depends on API functions: pthread_create().
- */
-
-#include <pthread.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-void *
-func(void * arg)
-{
- for (;;)
- { /* spin */ }
-}
-
-int
-main(int argc, char * argv[])
-{
- pthread_t id[2];
- int rc;
-
- /* Create two threads and compare their thread IDs.
- The threads will chew CPU, but ensure that their
- IDs will be valid for a long time :-). */
-
- pthread_create(&id[0], NULL, entry, NULL);
- pthread_create(&id[1], NULL, entry, NULL);
-
- if (pthread_equal(id[0], id[1]) == 0)
- {
- /* This is impossible. */
- abort();
- }
-
- /* Never reached. */
- return 0;
-}
diff --git a/tests/equal1.c b/tests/equal1.c
new file mode 100644
index 0000000..3b4c758
--- /dev/null
+++ b/tests/equal1.c
@@ -0,0 +1,34 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <windows.h>
+
+void * func(void * arg)
+{
+ printf("Hello world %d\n", (int) arg);
+ Sleep(2000);
+ return arg;
+}
+
+main()
+{
+ int rc;
+ pthread_t t1, t2;
+ rc = pthread_create(&t1, NULL, func, (void *) 1);
+ rc = pthread_create(&t1, NULL, func, (void *) 2);
+
+ puts("testing t1 and t2: ");
+ if (pthread_equal(t1, t2))
+ printf("equal\n");
+ else
+ printf("not equal\n");
+
+ puts("testing t1 on itself: ");
+ if (pthread_equal(t1,t1))
+ printf("equal\n");
+ else
+ printf("not equal\n");
+
+ Sleep(8000);
+
+ return 0;
+}