2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-01-27 13:42:22 +01:00
The ``++Monitor.Pulse++`` call releases the object on which it was called and wakes up the first thread waiting for the lock on that object. Significantly, it only releases _one_ lock, and if multiple locks are held when it is called deadlocks could result.
2020-06-30 12:48:39 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2020-06-30 12:48:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2020-06-30 12:48:39 +02:00
----
public void doSomething(Object obj)
{
lock (this) //first lock
{
lock (obj) { // second lock
// ...
Monitor.Pulse(obj); // Noncompliant; only the second lock is released
}
}
}
----
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Remove this "Monitor.Pulse" call; it only releases the lock on "xxx", leaving the one on "yyy" intact.
2021-09-20 15:38:42 +02:00
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== on 16 Jun 2015, 11:21:35 Tamas Vajk wrote:
\[~ann.campbell.2], could you please go through this C# specific version of the rule?
=== on 16 Jun 2015, 13:35:03 Ann Campbell wrote:
Looks good [~tamas.vajk]
include::../comments-and-links.adoc[]
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]