17 #include <itkFastMutexLock.h>
18 #include <itkMultiThreader.h>
19 #include <itkSemaphore.h>
36 itk::FastMutexLock *mutex;
37 itk::Semaphore *semaphore;
38 itk::Semaphore *mayIRun;
44 std::cout <<
"Getting thread info data... ";
45 itk::MultiThreader::ThreadInfoStruct *threadInfo =
static_cast<itk::MultiThreader::ThreadInfoStruct *
>(param);
49 std::cout <<
"[FAILED]" << std::endl;
52 std::cout <<
"[PASSED]" << std::endl;
54 std::cout <<
"Getting user data from thread... ";
55 UserData *userData =
static_cast<UserData *
>(threadInfo->UserData);
59 std::cout <<
"[FAILED]" << std::endl;
62 std::cout <<
"[PASSED]" << std::endl;
65 std::cout <<
"generate 10000 results";
66 for (
int i = 1; i <= 10000; ++i)
68 userData->mutex->Lock();
69 *(userData->intPointer) += 1;
70 userData->mutex->Unlock();
71 userData->semaphore->Up();
73 std::cout <<
"[PASSED]" << std::endl;
75 std::cout <<
"waiting for main thread's signal... " << std::endl;
77 userData->mayIRun->Down();
78 std::cout <<
"got main thread's signal... " << std::endl;
81 for (
int i = 1; i <= 10000; ++i)
83 userData->mutex->Lock();
84 *(userData->intPointer) += 1;
85 userData->mutex->Unlock();
88 userData->semaphore->Up();
90 return ITK_THREAD_RETURN_VALUE;
100 m_ResultAvailable->Initialize(0);
103 m_RunThreadRun->Initialize(0);
108 userData.intPointer = &localInt;
109 userData.mutex = m_Mutex.GetPointer();
110 userData.semaphore = m_ResultAvailable.GetPointer();
111 userData.mayIRun = m_RunThreadRun.GetPointer();
114 int thread_id = threader->SpawnThread(pointer, &userData);
117 for (
int i = 1; i <= 10000; ++i)
118 m_ResultAvailable->Down();
120 std::cout <<
"signaling by semaphore thread->main ";
121 if (localInt == 10000)
122 std::cout <<
"[PASSED]" << std::endl;
125 std::cout <<
"[FAILED] localInt == " << localInt << std::endl;
131 m_RunThreadRun->Up();
132 for (
int i = 1; i <= 10000; ++i)
139 std::cout <<
"waiting for thread's signal" << std::endl;
141 m_ResultAvailable->Down();
142 std::cout <<
"got thread's signal" << std::endl;
145 std::cout <<
"sharing a mutex protected variable among threads";
146 if (localInt == 20000)
147 std::cout <<
"[PASSED]" << std::endl;
150 std::cout <<
"[FAILED] localInt == " << localInt << std::endl;
155 std::cout <<
"waiting for idling thread ";
156 threader->TerminateThread(thread_id);
157 std::cout <<
"[PASSED]" << std::endl;
159 std::cout <<
"Whole test [PASSED]" << std::endl;
int mitkITKThreadingTest(int, char *[])
itk::SmartPointer< Self > Pointer
ITK_THREAD_RETURN_TYPE ThreadedFunction(void *param)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.