正在等待一个锁的FIFO线程?线程、正在等待、FIFO

由网友(无人问津)分享简介:让我们说我有以下的code Let's say I have the following codestatic class ...{static object myobj = new object();static void mymethod(){lock(myobj){// my code....}}}然后让...

让我们说我有以下的code

Let's say I have the following code

static class ...
{
    static object myobj = new object();

    static void mymethod()
    {
        lock(myobj)
        {
            // my code....
        }
    }
}

然后让我们说,虽然线程1具有线程2试图运行myMethod的锁。 它会等待锁被释放或者抛出一个异常?

Then let's say that while thread1 has the lock thread2 tries to run mymethod. Will it wait for the lock to be released or throw an exception?

如果它等待,是为了确保这样,如果其他线程进来,他们是FIFO?

If it does wait, is order ensured so that if additional threads come in they are FIFO?

推荐答案

更​​新我的回答: 它们进行排队,但顺序不是保证是FIFO中。

Updated my answer: They are queued, but the order is not guaranteed to be FIFO.

看看这个链接: http://www.albahari.com/threading/part2.aspx

阅读全文

相关推荐

最新文章