正在等待一个锁的FIFO线程? [英] Are threads waiting on a lock FIFO?

查看:136
本文介绍了正在等待一个锁的FIFO线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有以下的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

这篇关于正在等待一个锁的FIFO线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆