
Thread-at-a-time example in IGOR help

gregorK
I am starting to use multithreading techniques in my IGOR functions and I was lookin at the Thread-at-a-time example in IGOR help:
Function MTFillWaveThreadAtATime(dest) WAVE dest Variable ncol= DimSize(dest,1) Variable col,nthreads= ThreadProcessorCount Variable threadGroupID= ThreadGroupCreate(nthreads) for(col=0; col<ncol; col+=1) // Get index of a free thread - Requires Igor Pro 6.23 or later Variable threadIndex = ThreadGroupWait(threadGroupID,-2) - 1 if (threadIndex < 0) continue // No free threads yet endif ThreadStart threadGroupID, threadIndex, MyWorkerFunc(dest,col) endfor // Wait for all threads to finish do Variable threadGroupStatus = ThreadGroupWait(threadGroupID,100) while(threadGroupStatus != 0) Variable dummy= ThreadGroupRelease(threadGroupID) End
where I believe is a "bug". Namely in the for loop starting the
MyWorkerFunc
in the currently free threads (in the example filling a WAVE) in case where there is no free thread the worker function for the current col (the for loop index) will not be dispatched ever and therefore in the example case the matrix column col will not get filled. Can anyone confirm this? If I am not mistaken the example function would work as expected if one changes the if loop inside the for loop to if (threadIndex < 0) col -= 1 // retry to dispatch the thread with the same col index continue endif
Thanks,
Gregor
February 23, 2014 at 01:00 pm - Permalink