Exemple #1
0
void* test_many_mutex(void *threadid)
{
   // Declare local variables
   int tid = (int) threadid;

   // Thread starts here

   for (int i = 0; i < 1000; i++)
   {
      CarbonMutexLock(&my_mux1);
      CarbonMutexLock(&my_mux2);
      CarbonMutexLock(&my_mux3);
      if (i % 100 == 0)
         fprintf(stderr, "Thread %d got %dth lock...\n", tid, i);
      CarbonMutexUnlock(&my_mux3);
      CarbonMutexUnlock(&my_mux2);
      CarbonMutexUnlock(&my_mux1);
   }

   return NULL;
}
Exemple #2
0
void* test_many_mutex(void *threadid)
{
   // Declare local variables
   int tid = (int) threadid;

   // Thread starts here

   // FIXME: This should be in the main thread or something.
   if (tid == 0)
   {
      fprintf(stderr, "TestManyMutex(%d): Initting barrier.\n", (int)tid);
      // FIXME: shouldn't be hardcoding the barrier count here
      CarbonMutexInit(&my_mux1);
      CarbonMutexInit(&my_mux2);
      CarbonMutexInit(&my_mux3);
      fprintf(stderr, "TestManyMutex(%d): Barrier Initialized.\n", (int)tid);
   }
   else
   {
      sleep(1);
   }

   for (int i = 0; i < 1000; i++)
   {
      CarbonMutexLock(&my_mux1);
      CarbonMutexLock(&my_mux2);
      CarbonMutexLock(&my_mux3);
      if (i % 100 == 0)
         fprintf(stderr, "Thread %d got %dth lock...\n", tid, i);
      CarbonMutexUnlock(&my_mux3);
      CarbonMutexUnlock(&my_mux2);
      CarbonMutexUnlock(&my_mux1);
   }

   return NULL;
}