]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
From the OReilly book, page 15. Uses _create and _join.
authorJulian Seward <jseward@acm.org>
Wed, 10 Apr 2002 12:14:34 +0000 (12:14 +0000)
committerJulian Seward <jseward@acm.org>
Wed, 10 Apr 2002 12:14:34 +0000 (12:14 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@48

tests/pth_simple_threads.c [new file with mode: 0644]

diff --git a/tests/pth_simple_threads.c b/tests/pth_simple_threads.c
new file mode 100644 (file)
index 0000000..e42ae26
--- /dev/null
@@ -0,0 +1,44 @@
+
+#include <stdio.h>
+#include <pthread.h>
+
+int r1 = 0, r2 = 0;
+
+void do_one_thing ( int* ntimes )
+{
+  int i, j, x;
+  for (i = 0; i < 4; i++) {
+    printf ("doing one thing\n");
+    for (j = 0; j < 100000; j++) x = x + i;
+    (*ntimes)++;
+  }
+}
+
+void do_another_thing ( int* ntimes )
+{
+  int i, j, x;
+  for (i = 0; i < 4; i++) {
+    printf ("doing another\n");
+    for (j = 0; j < 100000; j++) x = x + i;
+    (*ntimes)++;
+  }
+}
+
+void do_wrap_up ( int one_times, int another_times )
+{
+  int total = one_times + another_times;
+  printf("wrap up: one thing %d, another %d, total %d\n",
+         one_times, another_times, total );
+}
+
+int main ( void )
+{
+  pthread_t t1, t2;
+  pthread_create( &t1, NULL, (void*)do_one_thing, (void*)&r1 );
+  pthread_create( &t2, NULL, (void*)do_another_thing, (void*)&r2 );
+  //  while (1) {}
+  pthread_join(t1, NULL);
+  pthread_join(t2, NULL);
+  do_wrap_up(r1,r2);
+  return 0;
+}