relationship between scope and synchronization context

113 views Asked by At

How do scope and synchronization context relate? With regards to this Search() method running in our WPF GUI thread:

private void Search()
{
    const int CPUs = 2;
    var doneEvents = new ManualResetEvent[CPUs];

    // Configure and launch threads using ThreadPool:
    for (int i = 0; i < CPUs; i++)
    {
        doneEvents[i] = new ManualResetEvent(false);
        var f = new Indexer(Paths[i], doneEvents[i]);
        ThreadPool.QueueUserWorkItem(f.WaitCallBack, i);
    }

    // Wait for all threads in pool 
    WaitHandle.WaitAll(doneEvents);
    Debug.WriteLine("Search completed!");
}

does the code above fail because we are trying to access one synchronization context from another in the same scope? Can scopes even span synchronization contexts?

0

There are 0 answers