Ask Question
26 September, 09:24

A multithreaded web server wishes to keep track of the number of requests it services (known as hits). Consider the two following strategies to prevent a race condition on the variable hits. The first strategy is to use a basic mutex lock when updating hits:int hits; mutex lock hit lock; hit lock. acquire (); hits++; hit lock. release (); A second strategy is to use an atomic integer:atomic t hits; atomic inc (& hits); Explain which of these two strategies is more efficient.

+5
Answers (1)
  1. 26 September, 09:53
    0
    Atomic integer strategy will be more efficient than a mutex. Technically, the atomic will lock the memory bus on most platforms. However, there are two ameliorating details It is impossible to suspend a thread during the memory bus lock, but it is possible to suspend a thread during a mutex lock. This is what lets you get a lockfree guarentee (which doesn't say anything about not locking
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “A multithreaded web server wishes to keep track of the number of requests it services (known as hits). Consider the two following ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers