C
C#14mo ago
Raki

why are thread.sleep, synchronous semaphore waits and other blocking calls harmful in async methods?

above is asked in a interview. what should be the answer. I replied that it will make the async operation useless since async will wait untill the process is executed in the mean time the thread will work on the next one
3 Replies
cap5lut
cap5lut14mo ago
yeah it basically senselessly blocks the thread from doing other work, so just needlessly consuming resources, might even end up in deadlocks that way
Tvde1
Tvde114mo ago
You are indeed right. Async/await is a framework to allow threads to start a task and do other stuff until the task is finished and signals the original method can be continued. By using blocking methods such as Thread.Sleep() you are keeping that thread occupied with waiting until the blocking operation completes. Did you have the impression you answered the question incorrectly or insufficiently?
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.