//////////////////////////////////////////////////////////////////////////////// // The Loki Library // Copyright (c) 2006 Peter Kümmel // Permission to use, copy, modify, distribute and sell this software for any // purpose is hereby granted without fee, provided that the above copyright // notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. // The author makes no representations about the // suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// // $Header: #define LOKI_CLASS_LEVEL_THREADING #ifndef LOKI_CLASS_LEVEL_THREADING #define LOKI_OBJECT_LEVEL_THREADING #endif #include "Thread.h" #include #include using namespace Loki; int g; int numThreads = 10; int loop = 5; struct A { A(){}; #define DO for(int i=0; i<10000000; i++) g++; void print(void* id) const { DO;Printf("%p: ----------------\n")(id); DO;Printf("%p: ---------------\n")(id); DO;Printf("%p: --------------\n")(id); DO;Printf("%p: -------------\n")(id); DO;Printf("%p: ------------\n")(id); DO;Printf("%p: -----------\n")(id); DO;Printf("%p: ----------\n")(id); DO;Printf("%p: ---------\n")(id); DO;Printf("%p: --------\n")(id); DO;Printf("%p: -------\n")(id); DO;Printf("%p: ------\n")(id); DO;Printf("%p: -----\n")(id); DO;Printf("%p: ----\n")(id); DO;Printf("%p: ---\n")(id); DO;Printf("%p: --\n")(id); DO;Printf("%p: -\n")(id); DO;Printf("%p: \n")(id); DO;Printf("%p: \n")(id); } }; typedef Loki::LockingPtr LPtr; typedef Loki::LockingPtr CLPtr; void* RunLocked(void *id) { volatile A a; static Loki::Mutex m; for(int i=0; iprint(id); } return 0; } void* RunConstLocked(void *id) { const volatile A a; static Loki::Mutex m; for(int i=0; iprint(id); } return 0; } void* Run(void *id) { A a; for(int i=0; i threads; for(int i=0; i(i))); } for(int i=0; istart(); Thread::JoinThreads(threads); Thread::DeleteThreads(threads); Printf("--------------------------------------------------------------------------------------\n"); Printf("--------------------------------------------------------------------------------------\n"); Printf("--------------------------------------------------------------------------------------\n"); for(int i=0; i(i))); } for(int i=0; istart(); Thread::JoinThreads(threads); Thread::DeleteThreads(threads); }