Elance Exams Answers PDF file

-- PDF FILE --
Download PDF file of elance Zoho Creator Exam Answers
elance-zoho-creator-exam.pdf

In the following class definition: class my_lock { std::atomic<int> data; public: my_lock() : data{1} {} void unlock() { data = 1; } void lock(); } which could be used to complete the lock function, assuming the purpose of the above code is to create a mutex-like locking mechanism? Assume C++11.

void my_lock::lock() { int exp(0); while (!data.compare_and_swap(exp, 1)) exp = 0; }
void my_lock::lock() { int exp(0); while (!data.compare_exchange_strong(exp, 1)) exp = 0; }
void my_lock::lock() { int exp(1); while (!data.compare_exchange_strong(exp, 0)) exp = 1; }
void my_lock::lock() { int exp(1); while (!data.compare_and_swap(exp, 0)) exp = 1; }
void my_lock::lock() { exp = 0; }
Top
  • Follows us our servcies
  • Facebook icon
  • Linkedin icon
  • twitter icon
  • rss icon
  • social icon