24 #include <core/threading/thread.h> 25 #include <core/threading/mutex.h> 36 for ( unsigned int i = 0; i < 1000000; i++) { \ 46 class ExampleMutexCountThread :
public Thread 56 ExampleMutexCountThread(
string s,
57 Mutex *m,
unsigned int *mutex_count,
unsigned int *non_mutex_count,
58 unsigned int sleep_time)
59 :
Thread(
"ExampMutexCountThread",
Thread::OPMODE_CONTINUOUS)
63 this->slt = sleep_time;
65 this->mc = mutex_count;
66 this->nmc = non_mutex_count;
75 unsigned int n = *nmc;
83 if ( m != NULL ) m->lock();
89 if ( m != NULL ) m->unlock();
92 cout << s <<
": mutex: " << *mc <<
"(non-mutex: " << *nmc <<
")" << endl;
94 if ( sl ) usleep(slt);
110 main(
int argc,
char **argv)
115 unsigned int mutex_count = 0;
116 unsigned int non_mutex_count = 0;
118 ExampleMutexCountThread *t1 =
new ExampleMutexCountThread(
"t1", m, &mutex_count, &non_mutex_count, 1000);
119 ExampleMutexCountThread *t2 =
new ExampleMutexCountThread(
"t2", m, &mutex_count, &non_mutex_count, 10000);
120 ExampleMutexCountThread *t3 =
new ExampleMutexCountThread(
"t3", m, &mutex_count, &non_mutex_count, 100000);
Fawkes library namespace.
Thread class encapsulation of pthreads.
Mutex mutual exclusion lock.