rspec/rules/S3889/why-dotnet.adoc
2023-06-07 12:01:33 +02:00

9 lines
859 B
Plaintext

`Thread.Suspend` and `Thread.Resume` can give unpredictable results, and both methods have been deprecated. Indeed, if `Thread.Suspend` is not used very carefully, a https://en.wikipedia.org/wiki/Thread_(computing)[thread] can be suspended while holding a https://en.wikipedia.org/wiki/Lock_(computer_science)[lock], thus leading to a https://en.wikipedia.org/wiki/Deadlock[deadlock].
There are other synchronization mechanisms that are safer and should be used instead, such as:
* `Monitor` provides a mechanism that synchronizes access to objects.
* `Mutex` provides a mechanism that synchronizes interprocess access to a protected resource.
* `Semaphore` provides a mechanism that allows limiting the number of threads that have access to a protected resources concurrently.
* `Events` enable a class to notify others when something of interest occurs.