Beispiel #1
0
SO_PUBLIC void
Thread_InterruptAndJoin(struct Thread *thread) {
	ASSERT (thread != NULL);
	Thread_Stop(thread);
	Thread_Interrupt(thread);
	Thread_Join(thread);
}
TEST(Thread, Join)
{
	void * result;
    thread = Thread_Create(threadEntry, 0);
    Thread_Start(thread);
    Thread_Join(thread, &result);
    Thread_Destroy(thread);
    LONGS_EQUAL(42, *((int *)result));
}
Beispiel #3
0
static void
TestSuite_RunParallel (TestSuite *suite) /* IN */
{
   ParallelInfo *info;
   Thread *threads;
   Mutex mutex;
   Test *test;
   int count = 0;
   int i;

   ASSERT (suite);

   Mutex_Init (&mutex);

   for (test = suite->tests; test; test = test->next) {
      count++;
   }

   threads = calloc (count, sizeof *threads);

   Memory_Barrier ();

   for (test = suite->tests, i = 0; test; test = test->next, i++) {
      info = calloc (1, sizeof *info);
      info->suite = suite;
      info->test = test;
      info->count = &count;
      info->mutex = &mutex;
      Thread_Create (&threads [i], TestSuite_ParallelWorker, info);
   }

   for (test = suite->tests, i = 0; test; test = test->next, i++) {
      Thread_Join(threads [i]);
   }

/*if (timeout < 0 || timeout > 600)
{
   timeout = 60;
}
#ifdef _WIN32
   Sleep (timeout * 1000);
#else
   sleep (timeout);
#endif
*/
   //fprintf (stderr, "Timed out, aborting!\n");

   //abort ();
}
Beispiel #4
0
TEST(MutexTest,IncControl)
{ Thread *pool[100];
  int i,N=100;
	counter c;
  init_counter(&c);
  EXPECT_EQ(c.n,0);
  for(i=0;i<N;++i)
  { pool[i] = Thread_Alloc(inc_ctl,(void*)&c); // <50ms>*100 = 5s
    ASSERT_NE(pool[i],(void*)NULL);
  }
  for(i=0;i<N;++i)
    Thread_Join(pool[i]);
  for(i=0;i<N;++i)
    Thread_Free(pool[i]);
  EXPECT_NE(c.n,N);
  Mutex_Free(c.lock);
}
Beispiel #5
0
int main(int argc,char* argv[])
{ Chan *chan;
  Thread*  threads[N];
  input_t  inputs[N];

  stop=0;
  item=0;

  chan = Chan_Alloc(16,sizeof(int));

  stop=0;
  { size_t i;
    ThreadProc procs[N] = { 
      consumer,
      consumer,
      consumer,
      consumer,
      producer,
      producer,
      producer,
      producer,
      producer,
    };
    for(i=0;i<N;++i)
    { inputs[i].id   = i;
      inputs[i].chan = chan;
    }
    for(i=0;i<N;++i)
    { threads[i] = Thread_Alloc(procs[i],(void*)(inputs+i));
      usleep(10);
    }
  }

  //usleep(100);
  Chan_Wait_For_Ref_Count(chan,N+1);
  stop=1;
  printf("*** Main: triggered stop ***"ENDL);
  { int i=0;
    for(i=0;i<N;++i)
      Thread_Join(threads[i]);
  }
  Chan_Close(chan);
  printf("Balance: (%d,%d) %s"ENDL,pmax,cmax,(pmax==cmax)?"Ok!":"Mismatch *****");
  return 0;
}
Beispiel #6
0
// This is required for proper operation of Thread_Free() on windows.  On
// PThread based systems, repeated joins are undefined but are not required for
// Thread_Free() to work.
TEST_F(ThreadTest,MultiJoin)
{ 
  EXPECT_EQ(Thread_Join(fortytwo_),(void*)42);
  EXPECT_EQ(Thread_Join(fortytwo_),(void*)42);
  EXPECT_EQ(Thread_Join(fortytwo_),(void*)42);
}