Skip to content

Lock keyword Lock type and thread starvation #107232

Answered by Clockwork-Muse
ladeak asked this question in Q&A
Discussion options

You must be logged in to vote

You're not even guaranteed that b and c will swap between them, c might release the resource and immediately "win" the lock race. The underlying OS mechanisms are not guaranteed to be fair. They are roughly FIFO, so threads will eventually make progress, but if that isn't sufficient you'd need to try other mitigations.

Generally speaking, you need to design your application in such a way that this isn't an issue. What, specifically, that needs to be depends entirely on what the resource is and what modifications you're trying to do.

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@ladeak
Comment options

Comment options

You must be logged in to vote
2 replies
@Clockwork-Muse
Comment options

Answer selected by ladeak
@ladeak
Comment options

Comment options

You must be logged in to vote
1 reply
@Clockwork-Muse
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants