本文整理汇总了C++中harness::SpinBarrier类的典型用法代码示例。如果您正苦于以下问题:C++ SpinBarrier类的具体用法?C++ SpinBarrier怎么用?C++ SpinBarrier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpinBarrier类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: operator
void operator()( int id ) const {
const int ITERS = 1000;
void *local[ITERS];
startB.wait();
for (int i=id*OBJ_CNT; i<(id+1)*OBJ_CNT; i++) {
afterTerm[i] = pool_malloc(pool, i%2? 8*1024 : 9*1024);
memset(afterTerm[i], i, i%2? 8*1024 : 9*1024);
crossThread[i] = pool_malloc(pool, i%2? 9*1024 : 8*1024);
memset(crossThread[i], i, i%2? 9*1024 : 8*1024);
}
for (int i=1; i<ITERS; i+=2) {
local[i-1] = pool_malloc(pool, 6*1024);
memset(local[i-1], i, 6*1024);
local[i] = pool_malloc(pool, 16*1024);
memset(local[i], i, 16*1024);
}
mallocDone.wait();
int myVictim = threadNum-id-1;
for (int i=myVictim*OBJ_CNT; i<(myVictim+1)*OBJ_CNT; i++)
pool_free(pool, crossThread[i]);
for (int i=0; i<ITERS; i++)
pool_free(pool, local[i]);
}
开发者ID:ElaraFX,项目名称:tbb,代码行数:25,代码来源:test_malloc_pools.cpp
示例2: operator
void operator() ( int id ) const {
ASSERT( id < 2, "Only two test driver threads are expected" );
// a barrier is required to ensure both threads started; otherwise the test may deadlock:
// the first thread would execute FireAndForgetTask at shutdown and wait for FafCanFinish,
// while the second thread wouldn't even start waiting for the loader lock hold by the first one.
if ( id == 0 ) {
driver_barrier.wait();
// Prepare global data
g_Root1 = new( tbb::task::allocate_root() ) tbb::empty_task;
g_Root2 = new( tbb::task::allocate_root() ) tbb::empty_task;
g_Root3 = new( tbb::task::allocate_root() ) tbb::empty_task;
g_Task = new( g_Root3->allocate_child() ) tbb::empty_task;
g_Root3->set_ref_count(2);
// Run tests
NativeParallelFor( NumTestFuncs, TestThreadBody() );
ASSERT( g_NumTestsExecuted == NumTestFuncs, "Test driver: Wrong number of tests executed" );
// This test checks the validity of temporarily restoring the value of
// the last TLS slot for a given key during the termination of an
// auto-initialized master thread (in governor::auto_terminate).
// If anything goes wrong, generic_scheduler::cleanup_master() will assert.
// The context for this task must be valid till the task completion.
tbb::task &r = *new( tbb::task::allocate_root(*g_Ctx) ) FireAndForgetTask;
r.spawn(r);
}
else {
tbb::task_group_context ctx;
g_Ctx = &ctx;
driver_barrier.wait();
spin_wait_until_eq( FafStarted, true );
UseAFewNewTlsKeys();
FafCanFinish = true;
spin_wait_until_eq( FafCompleted, true );
}
}
开发者ID:Multi2Sim,项目名称:m2s-bench-parsec-3.0-src,代码行数:35,代码来源:test_task_auto_init.cpp
示例3: operator
void operator()(int id) const {
barrier->wait();
Harness::Sleep(2*id);
void *o = pool_malloc(pool, id%2? 64 : 128*1024);
barrier->wait();
pool_free(pool, o);
}
开发者ID:jose-villegas,项目名称:VCTRenderer,代码行数:7,代码来源:test_malloc_pools.cpp
示例4: Run
void Run ( uint_t idx ) {
#if TBBTEST_USE_TBB
tbb::task_scheduler_init init;
#endif
AssertLive();
if ( idx == 0 ) {
ASSERT ( !m_taskGroup && !m_tasksSpawned, "SharedGroupBody must be reset before reuse");
m_taskGroup = new Concurrency::task_group;
Spawn( c_numTasks0 );
Wait();
if ( m_sharingMode & VagabondGroup )
m_barrier.wait();
else
DeleteTaskGroup();
}
else {
while ( m_tasksSpawned == 0 )
__TBB_Yield();
ASSERT ( m_taskGroup, "Task group is not initialized");
Spawn (c_numTasks1);
if ( m_sharingMode & ParallelWait )
Wait();
if ( m_sharingMode & VagabondGroup ) {
ASSERT ( idx == 1, "In vagabond mode SharedGroupBody must be used with 2 threads only" );
m_barrier.wait();
DeleteTaskGroup();
}
}
AssertLive();
}
开发者ID:HeliumProject,项目名称:ThreadBuildingBlocks,代码行数:30,代码来源:test_task_group.cpp
示例5: init
static void init(int num, rml::MemoryPool *pl, void **crThread, void **aTerm) {
threadNum = num;
pool = pl;
crossThread = crThread;
afterTerm = aTerm;
startB.initialize(threadNum);
mallocDone.initialize(threadNum);
}
开发者ID:ElaraFX,项目名称:tbb,代码行数:8,代码来源:test_malloc_pools.cpp
示例6: operator
void operator()(int id) const {
if (!id) {
Harness::LIBRARY_HANDLE lib =
Harness::OpenLibrary(TEST_LIBRARY_NAME("test_malloc_used_by_lib_dll"));
ASSERT(lib, "Can't load " TEST_LIBRARY_NAME("test_malloc_used_by_lib_dll"));
runPtr = Harness::GetAddress(lib, "callDll");
unloadCallback.lib = lib;
}
startBarr.wait();
(*runPtr)();
endBarr.wait(unloadCallback);
}
开发者ID:Zer0code,项目名称:LoLUpdater,代码行数:12,代码来源:test_malloc_used_by_lib.cpp
示例7: operator
size_t operator()(){
struct _{ static void retrieve_from_cache(self_type* _this, size_t thread_index){
parameter_pack& p = _this->m_parameter_pack;
access_sequence_type::iterator const begin_it =_this->m_access_sequence.begin()+ thread_index * _this->per_thread_sample_size;
access_sequence_type::iterator const end_it = begin_it + _this->per_thread_sample_size;
_this->m_barrier.wait();
tbb::tick_count start = tbb::tick_count::now();
size_t local_loops_count =0;
do {
size_t part_of_the_sample_so_far = (local_loops_count * p.time_check_granularity_ops) % _this->per_thread_sample_size;
access_sequence_type::iterator const iteration_begin_it = begin_it + part_of_the_sample_so_far;
access_sequence_type::iterator const iteration_end_it = iteration_begin_it +
(std::min)(p.time_check_granularity_ops, _this->per_thread_sample_size - part_of_the_sample_so_far);
for (access_sequence_type::iterator it = iteration_begin_it; it < iteration_end_it; ++it){
typename cache_type::handle h = _this->m_cache(*it);
micro_benchmarking::utils::busy_wait(p.time_of_item_use_usec);
micro_benchmarking::utils::disable_elimination(h.value());
}
++local_loops_count;
}while((tbb::tick_count::now()-start).seconds() < p.time_window_sec);
_this->loops_count+=local_loops_count;
}};
m_barrier.initialize(m_parameter_pack.threads_number);
NativeParallelFor(m_parameter_pack.threads_number,std::bind1st(std::ptr_fun(&_::retrieve_from_cache),this));
return loops_count * m_parameter_pack.time_check_granularity_ops;
}
开发者ID:cran,项目名称:RcppParallel,代码行数:31,代码来源:time_lru_cache_throughput.cpp
示例8: operator
void operator() (int) const {
tbb::internal::spin_wait_while_eq(gPtr, (void*)NULL);
scalable_free(gPtr);
my_barr->wait();
my_ward.wait_to_finish();
++FinishedTasks;
}
开发者ID:Zer0code,项目名称:LoLUpdater,代码行数:7,代码来源:test_malloc_init_shutdown.cpp
示例9: BusyBodyScoped
BusyBodyScoped( int nThread_, int workRatiox100_, tbb::enumerable_thread_specific<double> &locals_, int &unprotected_count_, bool test_throw_) :
locals(locals_),
nThread(nThread_),
WorkRatiox100(workRatiox100_),
unprotected_count(unprotected_count_),
test_throw(test_throw_) {
sBarrier.initialize(nThread_);
}
开发者ID:xiangyuan,项目名称:Unreal4,代码行数:8,代码来源:test_critical_section.cpp
示例10: ASSERT
/*override*/ tbb::task* execute() {
ASSERT( !(~theLocalState->m_flags & m_flag), NULL );
if( N < 2 )
return NULL;
bool globalBarrierActive = false;
if ( theLocalState->m_isMaster ) {
if ( theGlobalBarrierActive ) {
// This is the root task. Its N is equal to the number of threads.
// Spawn a task for each worker.
set_ref_count(N);
for ( int i = 1; i < N; ++i )
spawn( *new( allocate_child() ) FibTask(20, m_flag, m_observer) );
if ( theTestMode & tmSynchronized ) {
theGlobalBarrier.wait();
ASSERT( m_observer.m_entries >= N, "Wrong number of on_entry calls after the first barrier" );
// All the spawned tasks have been stolen by workers.
// Now wait for workers to spawn some more tasks for this thread to steal back.
theGlobalBarrier.wait();
ASSERT( !theGlobalBarrierActive, "Workers are expected to have reset this flag" );
}
else
theGlobalBarrierActive = false;
wait_for_all();
return NULL;
}
}
else {
if ( theGlobalBarrierActive ) {
if ( theTestMode & tmSynchronized ) {
theGlobalBarrier.wait();
globalBarrierActive = true;
}
theGlobalBarrierActive = false;
}
}
set_ref_count(3);
spawn( *new( allocate_child() ) FibTask(N-1, m_flag, m_observer) );
spawn( *new( allocate_child() ) FibTask(N-2, m_flag, m_observer) );
if ( globalBarrierActive ) {
// It's the first task executed by a worker. Release the master thread.
theGlobalBarrier.wait();
}
wait_for_all();
return NULL;
}
开发者ID:RandomDeveloperM,项目名称:UE4_Hairworks,代码行数:45,代码来源:test_task_scheduler_observer.cpp
示例11: Wait
void Wait () {
while ( m_threadsReady != m_numThreads )
__TBB_Yield();
const uint_t numSpawned = c_numTasks0 + c_numTasks1 * (m_numThreads - 1);
ASSERT ( m_tasksSpawned == numSpawned, "Wrong number of spawned tasks. The test is broken" );
REMARK("Max spawning parallelism is %u out of %u\n", Harness::ConcurrencyTracker::PeakParallelism(), g_MaxConcurrency);
if ( m_sharingMode & ParallelWait ) {
m_barrier.wait( &Harness::ConcurrencyTracker::Reset );
{
Harness::ConcurrencyTracker ct;
m_taskGroup->wait();
}
if ( Harness::ConcurrencyTracker::PeakParallelism() == 1 )
REPORT ( "Warning: No parallel waiting detected in TestParallelWait\n" );
m_barrier.wait();
}
else
m_taskGroup->wait();
ASSERT ( m_tasksSpawned == numSpawned, "No tasks should be spawned after wait starts. The test is broken" );
ASSERT ( s_tasksExecuted == numSpawned, "Not all spawned tasks were executed" );
}
开发者ID:HeliumProject,项目名称:ThreadBuildingBlocks,代码行数:21,代码来源:test_task_group.cpp
示例12: operator
void operator()(int thread_id ) const {
bool existed;
sBarrier.wait();
for(int i = 0; i < nIters; ++i ) {
existed = thread_id & 1;
int oldval = locals->local(existed);
ASSERT(existed == (i > 0), "Error on first reference");
ASSERT(!existed || (oldval == thread_id), "Error on fetched value");
existed = thread_id & 1;
locals->local(existed) = thread_id;
ASSERT(existed, "Error on assignment");
}
}
开发者ID:gomez-addams,项目名称:intel-tbb,代码行数:13,代码来源:test_combinable.cpp
示例13: exercise
void State::exercise( bool is_owner ) {
barrier.wait();
if( is_owner ) {
Cover(0);
if( ja.try_acquire() ) {
Cover(1);
++job_created;
ja.set_and_release(job);
Cover(2);
if( ja.try_acquire() ) {
Cover(3);
ja.release();
Cover(4);
if( ja.try_acquire() ) {
Cover(5);
ja.release();
}
}
Cover(6);
} else {
Cover(7);
}
if( DelayMask&1<<N ) {
while( !job_received )
__TBB_Yield();
}
} else {
// Using extra bit of DelayMask for choosing whether to run wait_for_job or not.
if( DelayMask&1<<N ) {
rml::job* j= &ja.wait_for_job();
if( j!=&job ) REPORT("%p\n",j);
ASSERT( j==&job, NULL );
job_received = true;
}
Cover(8);
}
rml::job* j;
if( ja.try_plug(j) ) {
ASSERT( j==&job || !j, NULL );
if( j ) {
Cover(9+is_owner);
++job_destroyed;
} else {
__TBB_ASSERT( !is_owner, "owner failed to create job but plugged self" );
Cover(11);
}
} else {
Cover(12+is_owner);
}
}
开发者ID:glycerine,项目名称:shore-mt,代码行数:50,代码来源:test_job_automaton.cpp
示例14: TestMain
int TestMain () {
if ( P < 2 )
return Harness::Skipped;
theNumObservers = 0;
theWorkersBarrier.initialize(P);
// Fully- and under-utilized mode
for ( int M = 1; M < P; M <<= 1 ) {
if ( M > P/2 ) {
ASSERT( P & (P-1), "Can get here only in case of non power of two cores" );
M = P/2;
if ( M & (M-1) )
break; // Already tested this configuration
}
int T = P / M;
ASSERT( T > 1, NULL );
REMARK( "Masters: %d; Arena size: %d\n", M, T );
theMasterBarrier.initialize(M);
theGlobalBarrier.initialize(M * T);
TestObserver(M, T, 0);
TestObserver(M, T, tmLocalObservation | ( T==P? tmAutoinitialization : 0) );
CleanLocalState();
TestObserver(M, T, tmSynchronized);
TestObserver(M, T, tmSynchronized | tmLocalObservation
#if __TBB_TASK_ARENA
| ( T==P? tmLeavingControl : 0)
#endif
);
}
// Oversubscribed mode
for ( int i = 0; i < 5; ++i ) {
REMARK( "Masters: %d; Arena size: %d\n", P-1, P );
TestObserver(P-1, P, 0);
TestObserver(P-1, P, tmLocalObservation);
}
Harness::Sleep(20);
return Harness::Done;
}
开发者ID:RandomDeveloperM,项目名称:UE4_Hairworks,代码行数:37,代码来源:test_task_scheduler_observer.cpp
示例15: operator
void operator()(const int tid) const {
sBarrier.wait();
for(int i=0; i < nIters; ++i) {
Harness::Sleep( tid * tickCounts );
tbb::tick_count t0 = tbb::tick_count::now();
mySem.P();
tbb::tick_count t1 = tbb::tick_count::now();
tottime[tid] += (t1-t0).seconds();
int curval = ++pCount;
if(curval > ourCounts[tid]) ourCounts[tid] = curval;
Harness::Sleep( innerWait );
--pCount;
ASSERT((int)pCount >= 0, NULL);
mySem.V();
}
}
开发者ID:Zer0code,项目名称:LoLUpdater,代码行数:16,代码来源:test_semaphore.cpp
示例16: operator
void operator()(const int /* threadID */ ) const {
int nIters = MAX_WORK/nThread;
sBarrier.wait();
tbb::tick_count t0 = tbb::tick_count::now();
for(int j = 0; j < nIters; j++) {
for(int i = 0; i < MAX_WORK * (100 - WorkRatiox100); i++) {
locals.local() += 1.0;
}
{
tbb::critical_section::scoped_lock my_lock(cs);
for(int i = 0; i < MAX_WORK * WorkRatiox100; i++) {
locals.local() += 1.0;
}
unprotected_count++;
}
}
locals.local() = (tbb::tick_count::now() - t0).seconds();
}
开发者ID:xiangyuan,项目名称:Unreal4,代码行数:19,代码来源:test_critical_section.cpp
示例17: testProducerConsumer
// -- test of producer/consumer with atomic buffer cnt and semaphore
// nTokens are total number of tokens through the pipe
// pWait is the wait time for the producer
// cWait is the wait time for the consumer
void testProducerConsumer( unsigned totTokens, unsigned nTokens, unsigned pWait, unsigned cWait) {
semaphore pSem;
semaphore cSem;
tbb::atomic<unsigned> pTokens;
tbb::atomic<unsigned> cTokens;
cTokens = 0;
unsigned cBuffer[MAX_TOKENS];
FilterBase* myFilters[2]; // one producer, one consumer
REMARK("Testing producer/consumer with %lu total tokens, %lu tokens at a time, producer wait(%lu), consumer wait (%lu)\n", totTokens, nTokens, pWait, cWait);
ASSERT(nTokens <= MAX_TOKENS, "Not enough slots for tokens");
myFilters[0] = new FilterBase(imaProducer, totTokens, pTokens, cTokens, pWait, cSem, pSem, (unsigned *)NULL, &(cBuffer[0]));
myFilters[1] = new FilterBase(imaConsumer, totTokens, cTokens, pTokens, cWait, pSem, cSem, cBuffer, (unsigned *)NULL);
pTokens = nTokens;
ProduceConsumeBody myBody(myFilters);
sBarrier.initialize(2);
NativeParallelFor(2, myBody);
delete myFilters[0];
delete myFilters[1];
}
开发者ID:Zer0code,项目名称:LoLUpdater,代码行数:23,代码来源:test_semaphore.cpp
示例18: Consume
void FilterBase::Consume(const int /*tid*/) {
unsigned myToken;
sBarrier.wait();
do {
while(!myTokens)
mySem.P();
// we have a slot available.
--myTokens; // moving this down reduces spurious wakeups
myToken = myBuffer[curToken&(MAX_TOKENS-1)];
if(myToken) {
ASSERT(myToken == curToken*3+1, "Error in received token");
++curToken;
Harness::Sleep(myWait);
unsigned temp = ++otherTokens;
if(temp == 1)
nextSem.V();
}
} while(myToken);
// end of processing
ASSERT(curToken + 1 == totTokens, "Didn't receive enough tokens");
}
开发者ID:Zer0code,项目名称:LoLUpdater,代码行数:21,代码来源:test_semaphore.cpp
示例19: Produce
// send a bunch of non-Null "tokens" to consumer, then a NULL.
void FilterBase::Produce(const int /*tid*/) {
nextBuffer[0] = 0; // just in case we provide no tokens
sBarrier.wait();
while(totTokens) {
while(!myTokens)
mySem.P();
// we have a slot available.
--myTokens; // moving this down reduces spurious wakeups
--totTokens;
if(totTokens)
nextBuffer[curToken&(MAX_TOKENS-1)] = curToken*3+1;
else
nextBuffer[curToken&(MAX_TOKENS-1)] = (unsigned)NULL;
++curToken;
Harness::Sleep(myWait);
unsigned temp = ++otherTokens;
if(temp == 1)
nextSem.V();
}
nextSem.V(); // final wakeup
}
开发者ID:Zer0code,项目名称:LoLUpdater,代码行数:22,代码来源:test_semaphore.cpp
示例20: operator
void operator()( int i ) const {
theLocalState->m_isMaster = true;
uintptr_t f = i <= MaxFlagIndex ? 1<<i : 0;
MyObserver o(f);
if ( theTestMode & tmSynchronized )
theMasterBarrier.wait();
// when mode is local observation but not synchronized and when num threads == default
if ( theTestMode & tmAutoinitialization )
o.observe(true); // test autoinitialization can be done by observer
// when mode is local synchronized observation and when num threads == default
if ( theTestMode & tmLeavingControl )
o.test_leaving();
// Observer in enabled state must outlive the scheduler to ensure that
// all exit notifications are called.
tbb::task_scheduler_init init(m_numThreads);
// when local & non-autoinitialized observation mode
if ( theTestMode & tmLocalObservation )
o.observe(true);
for ( int j = 0; j < 2; ++j ) {
tbb::task &t = *new( tbb::task::allocate_root() ) FibTask(m_numThreads, f, o);
tbb::task::spawn_root_and_wait(t);
thePrevMode = theTestMode;
}
if( o.is_leaving_test() ) {
REMARK( "Testing on_scheduler_leaving()\n");
ASSERT(o.m_workerEntries > 0, "Unbelievable");
// TODO: start from 0?
for ( int j = o.m_workerExits; j < o.m_workerEntries; j++ ) {
REMARK( "Round %d: entries %d, exits %d\n", j, (int)o.m_workerEntries, (int)o.m_workerExits );
ASSERT_WARNING(o.m_workerExits == j, "Workers unexpectedly leaved arena");
o.dismiss_one();
double n_seconds = 5;
(Harness::TimedWaitWhileEq(n_seconds))(o.m_workerExits, j);
ASSERT( n_seconds >= 0, "Time out while waiting for a worker to leave arena");
__TBB_Yield();
}
}
}
开发者ID:RandomDeveloperM,项目名称:UE4_Hairworks,代码行数:38,代码来源:test_task_scheduler_observer.cpp
注:本文中的harness::SpinBarrier类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论