enable poxix MultiThreading sample under Linux

This commit is contained in:
erwincoumans
2013-07-18 21:18:09 -07:00
parent 12a4480d08
commit 2f0fd80c9c
8 changed files with 193 additions and 440 deletions

View File

@@ -4,8 +4,8 @@ Copyright (c) 2010 Erwin Coumans http://bulletphysics.org
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
@@ -17,7 +17,7 @@ subject to the following restrictions:
/// You can start threads and perform a blocking wait for completion
/// Under Windows it uses Win32 Threads. On Mac and Linux it uses pthreads. On PlayStation 3 Cell SPU it uses SPURS.
/// June 2010
/// June 2010
/// New: critical section/barriers and non-blocking pollingn for completion, currently Windows only
void SampleThreadFunc(void* userPtr,void* lsMemory);
@@ -26,20 +26,19 @@ void* SamplelsMemoryFunc();
#include <stdio.h>
//#include "BulletMultiThreaded/PlatformDefinitions.h"
#ifdef USE_PTHREADS
//#ifdef __APPLE__
#include "BulletMultiThreaded/PosixThreadSupport.h"
#ifndef _WIN32
#include "b3PosixThreadSupport.h"
b3ThreadSupportInterface* createThreadSupport(int numThreads)
{
PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads",
b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads",
SampleThreadFunc,
SamplelsMemoryFunc,
numThreads);
b3ThreadSupportInterface* threadSupport = new PosixThreadSupport(constructionInfo);
b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo);
return threadSupport;
}
@@ -51,12 +50,12 @@ b3ThreadSupportInterface* createThreadSupport(int numThreads)
b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",SampleThreadFunc,SamplelsMemoryFunc,numThreads);
b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo);
return threadSupport;
}
}
#endif
struct SampleArgs
{
SampleArgs()
@@ -122,8 +121,7 @@ int main(int argc,char** argv)
b3ThreadSupportInterface* threadSupport = createThreadSupport(numThreads);
threadSupport->startThreads();
for (int i=0;i<threadSupport->getNumTasks();i++)
{
@@ -131,13 +129,13 @@ int main(int argc,char** argv)
b3Assert(storage);
storage->threadId = i;
}
SampleArgs args;
args.m_cs = threadSupport->createCriticalSection();
args.m_cs->setSharedParam(0,100);
int arg0,arg1;
int i;
for (i=0;i<numThreads;i++)
@@ -145,7 +143,7 @@ int main(int argc,char** argv)
threadSupport->sendRequest(B3_THREAD_SCHEDULE_TASK, (void*) &args, i);
}
bool blockingWait =true;
bool blockingWait =false;
if (blockingWait)
{
for (i=0;i<numThreads;i++)
@@ -155,25 +153,19 @@ int main(int argc,char** argv)
}
} else
{
#if _WIN32
int numActiveThreads = numThreads;
while (numActiveThreads)
{
if (((b3Win32ThreadSupport*)threadSupport)->isTaskCompleted(&arg0,&arg1,0))
if (threadSupport->isTaskCompleted(&arg0,&arg1,0))
{
numActiveThreads--;
printf("numActiveThreads = %d\n",numActiveThreads);
} else
{
printf("polling\n");
// printf("polling..");
}
};
#else
btAssert(0);
printf("non-blocking wait is not supported on this platform\n");
exit(0);
#endif
}
printf("stopping threads\n");