Multiple Thread with dependencies

原文链接:http://www.cnblogs.com/pangpangxiong/archive/2009/11/10/1599453.html

 

Original Articles comes from http://msdn.microsoft.com/en-us/magazine/dd569760.aspx

However, I met problems. threads in parallel enters into dead lock.  My implement is a littile different with this article. I am using while to check threads. But if doing this, this thread will always hold the lock. Any idea? 

Multiple Thread with dependenciesMultiple Thread with dependenciesCode
         while (_operations.Count != 0)
            {
                lock (_stateLock)
                {
                    using (_doneEvent = new ManualResetEvent(false))
                    {
                        {
                            foreach (var op in _operations.Values)
                            {
                                if (op.NumRemainingDependencies == 0)
                                {
                                    ThreadPool.UnsafeQueueUserWorkItem(state =>
                                            ProcessOperation((OperationData)state), op);
                                    _remainingCount++;
                                }
                            }
                            Console.WriteLine("First round!!");
                            _doneEvent.WaitOne();
                        }
                    }
                }

check thread satus, and found it is blocked by execute funciton.

Multiple Thread with dependenciesMultiple Thread with dependenciesCode
Incorrect argument: | 
0:006> !SyncBlk 
Index         SyncBlock MonitorHeld Recursion Owning Thread Info          SyncBlock Owner
    3 000000000092f278            7         1 00000000000e8f70  16f8   0   0000000002884100 System.Object
-----------------------------

Check the code, no doubt that the lock is always held by the execute funciton, thread 6.

It doesn't has chance to release lock before it is waiting the statelock

 

转载于:https://www.cnblogs.com/pangpangxiong/archive/2009/11/10/1599453.html

上一篇:Educational Codeforces Round 71 (Rated for Div. 2) B - Square Filling


下一篇:CodeForces681C - Heap Operations - 优先队列+模拟