Ask Question
23 August, 16:01

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.

+4
Answers (1)
  1. 23 August, 19:39
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers