Example #1
0
int main(int argc,char** argv)
{
	int numThreads = 8;

	b3ThreadSupportInterface* threadSupport = createThreadSupport(numThreads);



	for (int i=0;i<threadSupport->getNumTasks();i++)
	{
		SampleThreadLocalStorage* storage = (SampleThreadLocalStorage*)threadSupport->getThreadLocalMemory(i);
		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++)
	{
		threadSupport->sendRequest(B3_THREAD_SCHEDULE_TASK, (void*) &args, i);
	}

	bool blockingWait =false;
	if (blockingWait)
	{
		for (i=0;i<numThreads;i++)
		{
			threadSupport->waitForResponse(&arg0,&arg1);
			printf("finished waiting for response: %d %d\n", arg0,arg1);
		}
	} else
	{
		int numActiveThreads = numThreads;
		while (numActiveThreads)
		{
			if (threadSupport->isTaskCompleted(&arg0,&arg1,0))
			{
				numActiveThreads--;
				printf("numActiveThreads = %d\n",numActiveThreads);

			} else
			{
//				printf("polling..");
			}
		};
	}

printf("stopping threads\n");

	delete threadSupport;
	printf("Press ENTER to quit\n");
	getchar();
	return 0;
}
Example #2
0
 void init()
 {
     int maxNumWorkerThreads = BT_MAX_THREAD_COUNT - 1;
     m_threadSupport = createThreadSupport( maxNumWorkerThreads, WorkerThreadFunc, WorkerThreadAllocFunc, "TaskScheduler" );
     m_jobContext.m_queueLock = m_threadSupport->createCriticalSection();
     for ( int i = 0; i < maxNumWorkerThreads; i++ )
     {
         WorkerThreadLocalStorage* storage = (WorkerThreadLocalStorage*) m_threadSupport->getThreadLocalMemory( i );
         btAssert( storage );
         storage->threadId = i;
         storage->status = WorkerThreadStatus::kSleeping;
     }
     setWorkersActive( false ); // no work for them yet
 }
    virtual void    initPhysics()
    {
        b3Printf("initPhysics");
        
        

        m_threadSupport = createThreadSupport(m_numThreads);



        for (int i=0;i<m_threadSupport->getNumTasks();i++)
        {
            SampleThreadLocalStorage* storage = (SampleThreadLocalStorage*)m_threadSupport->getThreadLocalMemory(i);
            b3Assert(storage);
            storage->threadId = i;
        }


        
        args.m_cs = m_threadSupport->createCriticalSection();
        args.m_cs->setSharedParam(0,100);
        
        for (int i=0;i<100;i++)
        {
            SampleJob1* job = new SampleJob1(i);
            args.submitJob(job);
        }

       
        int i;
        for (i=0;i<m_numThreads;i++)
        {
            m_threadSupport->runTask(B3_THREAD_SCHEDULE_TASK, (void*) &args, i);
        }
         b3Printf("Threads started");

    }
Example #4
0
int main(int argc,char** argv)
{
	int numThreads = 8;

	btThreadSupportInterface* threadSupport = createThreadSupport(numThreads);

	
	threadSupport->startSPU();

	for (int i=0;i<threadSupport->getNumTasks();i++)
	{
		SampleThreadLocalStorage* storage = (SampleThreadLocalStorage*)threadSupport->getThreadLocalMemory(i);
		btAssert(storage);
		storage->threadId = i;
	}
	

	SampleArgs	args;
	args.m_cs = threadSupport->createCriticalSection();
	args.m_cs->setSharedParam(0,100);

	
		unsigned int arg0,arg1;
	int i;
	for (i=0;i<numThreads;i++)
	{
		threadSupport->sendRequest(1, (ppu_address_t) &args, i);
	}

	bool blockingWait =true;
	if (blockingWait)
	{
		for (i=0;i<numThreads;i++)
		{
			threadSupport->waitForResponse(&arg0,&arg1);
			printf("finished waiting for response: %d %d\n", arg0,arg1);
		}
	} else
	{
#if _WIN32
		int numActiveThreads = numThreads;
		while (numActiveThreads)
		{
			if (((Win32ThreadSupport*)threadSupport)->isTaskCompleted(&arg0,&arg1,0))
			{
				numActiveThreads--;
				printf("numActiveThreads = %d\n",numActiveThreads);

			} else
			{
				printf("polling\n");
			}
		};
#else
	btAssert(0);
	printf("non-blocking wait is not supported on this platform\n");
	exit(0);
#endif
	}

printf("stopping threads\n");

	delete threadSupport;
	printf("Press ENTER to quit\n");
	getchar();
	return 0;
}