Back to index

glibc  2.9
tst-thrlock.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <pthread.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <gnu/lib-names.h>
00007 
00008 static void *
00009 tf (void *arg)
00010 {
00011   void *h = dlopen (LIBM_SO, RTLD_LAZY);
00012   if (h == NULL)
00013     {
00014       printf ("dlopen failed: %s\n", dlerror ());
00015       exit (1);
00016     }
00017   if (dlsym (h, "sin") == NULL)
00018     {
00019       printf ("dlsym failed: %s\n", dlerror ());
00020       exit (1);
00021     }
00022   if (dlclose (h) != 0)
00023     {
00024       printf ("dlclose failed: %s\n", dlerror ());
00025       exit (1);
00026     }
00027   return NULL;
00028 }
00029 
00030 
00031 static int
00032 do_test (void)
00033 {
00034 #define N 10
00035   pthread_t th[N];
00036   for (int i = 0; i < N; ++i)
00037     {
00038       int e = pthread_create (&th[i], NULL, tf, NULL);
00039       if (e != 0)
00040        {
00041          printf ("pthread_create failed with %d (%s)\n", e, strerror (e));
00042          return 1;
00043        }
00044     }
00045   for (int i = 0; i < N; ++i)
00046     {
00047       void *res;
00048       int e = pthread_join (th[i], &res);
00049       if (e != 0 || res != NULL)
00050        {
00051          puts ("thread failed");
00052          return 1;
00053        }
00054     }
00055   return 0;
00056 }
00057 
00058 #define TEST_FUNCTION do_test ()
00059 #include "../test-skeleton.c"