Skip to content

Commit 1d2cee2

Browse files
committed
fixed raise condition in taskscheduler_new
1 parent 1e423b1 commit 1d2cee2

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

common/tasking/taskscheduler_new.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ namespace embree
119119

120120
TaskSchedulerNew::TaskSchedulerNew(size_t numThreads, bool spinning)
121121
: threadCounter(numThreads), createThreads(true), terminate(false), anyTasksRunning(0), active(false), spinning(spinning),
122-
task_set_function(nullptr)
122+
task_set_function(nullptr), masterThread(0,this)
123123
{
124124
for (size_t i=0; i<MAX_THREADS; i++)
125125
threadLocal[i] = NULL;
@@ -317,7 +317,7 @@ namespace embree
317317
if (executeTaskSet(thread))
318318
continue;
319319
#endif
320-
320+
321321
/* work on available task */
322322
steal_loop(thread,
323323
[&] () { return anyTasksRunning > 0; },
@@ -407,26 +407,27 @@ namespace embree
407407
for (size_t i=0; i<workingThreads; i++)
408408
{
409409
const size_t otherThreadIndex = thread_task_size[i].second;
410-
if (!threadLocal[otherThreadIndex])
410+
Thread* othread = threadLocal[otherThreadIndex];
411+
if (!othread)
411412
continue;
412413

413-
if (threadLocal[otherThreadIndex]->tasks.steal(thread))
414+
if (othread->tasks.steal(thread))
414415
return true;
415416
}
416417
/* nothing found this time, do another round */
417418

418419
#else
419420
for (size_t i=1; i<threadCount; i++)
420-
//for (size_t i=1; i<32; i++)
421421
{
422422
__pause_cpu(32);
423423
size_t otherThreadIndex = threadIndex+i;
424424
if (otherThreadIndex >= threadCount) otherThreadIndex -= threadCount;
425425

426-
if (!threadLocal[otherThreadIndex])
426+
Thread* othread = threadLocal[otherThreadIndex];
427+
if (!othread)
427428
continue;
428-
429-
if (threadLocal[otherThreadIndex]->tasks.steal(thread))
429+
430+
if (othread->tasks.steal(thread))
430431
return true;
431432
}
432433
#endif

common/tasking/taskscheduler_new.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ namespace embree
246246

247247
assert(!active);
248248
active = true;
249-
Thread thread(0,this);
249+
Thread& thread = masterThread;
250250
threadLocal[0] = &thread;
251251
setThread(&thread);
252252
thread.tasks.push_right(thread,size,closure);
@@ -274,7 +274,7 @@ namespace embree
274274

275275
assert(!active);
276276
active = true;
277-
Thread thread(0,this);
277+
Thread& thread = masterThread;
278278
threadLocal[0] = &thread;
279279
setThread(&thread);
280280

@@ -376,6 +376,7 @@ namespace embree
376376
__dllexport2 static TaskSchedulerNew* global_instance();
377377

378378
private:
379+
Thread masterThread;
379380
static TaskSchedulerNew* g_instance;
380381
static __thread Thread* thread_local_thread;
381382

0 commit comments

Comments
 (0)