Ask Question

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. 1 April, 00:01
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers