codementor on Nostr: Learn: Deadlock Thread 1 holds lock A and waits for B. Thread 2 holds B and waits for ...
Learn: Deadlock
Thread 1 holds lock A and waits for B. Thread 2 holds B and waits for A. Both wait forever.
It needs four things at once:
1. Only one thread can hold a lock.
2. A thread holds one lock while it waits for another.
3. Nobody can take a lock away.
4. The waiting forms a circle.
Prevent it: take locks in the same order, hold them briefly, use timeouts (Monitor.TryEnter).
Read more:
https://learn.microsoft.com/en-us/dotnet/standard/threading/managed-threading-best-practices#tip · TIP-079
Published at
2026-10-09 16:32:44 UTCEvent JSON
{
"id": "7631c7ab4b1214aee91517841d1ffbaeb2eb95a6b5c0cb66e5fc375eefe34a97",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1791563564,
"kind": 1,
"tags": [
[
"t",
"tip"
]
],
"content": "Learn: Deadlock\n\nThread 1 holds lock A and waits for B. Thread 2 holds B and waits for A. Both wait forever.\nIt needs four things at once:\n1. Only one thread can hold a lock.\n2. A thread holds one lock while it waits for another.\n3. Nobody can take a lock away.\n4. The waiting forms a circle.\nPrevent it: take locks in the same order, hold them briefly, use timeouts (Monitor.TryEnter).\n\nRead more: https://learn.microsoft.com/en-us/dotnet/standard/threading/managed-threading-best-practices\n\n#tip · TIP-079",
"sig": "b0abd514b2520ed8ea845bc1e3c70a9a1c7d99fb90a9cbc169f75cee994f74b37a112b39e839e88fcd2c12ae37253c35c08e5612e8cf90e8c94f26767993f60c"
}