Exemplo n.º 1
0
        public void StartThreads()
        {
            for (int i = 0; i < m_numOfThreads; i++)
            {
                m_threads[i]         = new Thread(Worker);
                m_threadExecInfos[i] = new ThreadExecInfo(i);
                m_eventsDone[i]      = m_threadExecInfos[i].EventDone;

                m_threads[i].Start(m_threadExecInfos[i]);
            }
        }
Exemplo n.º 2
0
        private void Worker(object param)
        {
            ThreadExecInfo threadExecInfo = param as ThreadExecInfo;

            WaitHandle[] waitHandles = { threadExecInfo.EventGo, threadExecInfo.EventFinish };

            m_initThread(threadExecInfo.Id);

            while (true)
            {
                int index = WaitHandle.WaitAny(waitHandles);

                if (index == INDEX_FINISH)
                {
                    threadExecInfo.EventDone.Set();
                    return;
                }
                Debug.Assert(index == INDEX_GO, "Unexpected wait result.");

                m_executeThread(threadExecInfo.Id);

                threadExecInfo.EventDone.Set();
            }
        }
Exemplo n.º 3
0
        public void StartThreads()
        {
            for (int i = 0; i < m_numOfThreads; i++)
            {
                m_threads[i] = new Thread(Worker);
                m_threads[i].Name = "Task Executor Thread #" + i;
                m_threadExecInfos[i] = new ThreadExecInfo(i);
                m_eventsDone[i] = m_threadExecInfos[i].EventDone;

                m_threads[i].Start(m_threadExecInfos[i]);
            }
        }