1
Vote

TaskMeter.Start, End in try/finally block by multi-threads causes TaskoMeter to not exit

description

When using PerformanceTestMethod and running in TaskoMeter, TaskoMeter never exits sometimes when calls to Start in a try and End in a finally within a task (with multiple instances).
 
Here is an example:
 
 
        var workerTasks = PatternFactory.StartPipelineStageWorkers(numWorkers, inputPairs, outputPairs
            , (workerIdx, pair) => {
 
                try
                {
                    tm.Start();
                    Interlocked.Increment(ref start);
                    // Allow the UI to see where we're at
                    if (_enableProgressStateUpdates)
                    {
                        lock (workersProgressArray)
                            workersProgressArray[workerIdx] = pair;
                    }
 
                    pair.Score = ImageRegionUtil.ComputeMatchScore(
                        pair.SourceRegion.Heuristic
                        , pair.TargetRegion.Heuristic
                        , useStdDeviation);
 
                    Interlocked.Increment(ref _stage3_regionPairsWithScoresComputedCount);
                    Interlocked.Increment(ref count);
 
                    OnWorkitemProcessed();
 
                    return pair;
                }
 
                finally
                {
                    tm.End();
                    Interlocked.Increment(ref stop);
                }
            }, uiCT);

comments

geof23 wrote Jun 10, 2011 at 7:30 PM

BTW, after attaching to mcut, here is the call stack:
user32.dll!_user32.dll!_NtUserWaitMessage@0() + 0x15 bytes
user32.dll!_NtUserWaitMessage@0()  + 0x15 bytes 
[External Code] 
Microsoft.Concurrency.Taskometer.dll!Microsoft.Concurrency.TestTools.TaskoMeter.Metering.MeasureInteractively.AnonymousMethod__0() Line 44 + 0x8 bytes  C#
[External Code] 
kernel32.dll!@BaseThreadInitThunk@12()  + 0x12 bytes    
ntdll.dll!___RtlUserThreadStart@8()  + 0x27 bytes   
ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes    

wrote Feb 13, 2013 at 10:14 PM