我想知道,如果每个线程使用它的方法是在此代码:
List<thread> threadArray= new List<thread>();
int numberOfWorkers = 10;
EventWaitHandle ewh = AutoResetEvent(false);
Queue<string> container = new Queue<string>();
object sync = new object();
for(int i = 0; i < numberOfWorkers; i++)
{
Thread t = new Thread(Worker);
threadArray.Add(t);
threadArray[i].Start();
}
public void Producer(string task)
{
lock(sync)
{
container.Enqueue(task);
}
ewh.Set();
}
public void Worker()
{
lock(sync)
{
string temp = container.Dequeue();
}
// do some work
// after work is complete wait...
ewh.WaitOne();
}</string></string></thread></thread>
因此,基本上就是我要问的是,如果每个线程使用它的"自己"的辅助方法,或者是他们(线程)共享这个单一的辅助方法吗?