Question

The curses display library is considered not to be “thread safe”. Two software architectures that will...

The curses display library is considered not to be “thread safe”. Two
software architectures that will ensure that curses library functions
are called safely are:
• Place all curses calls within a mutex guard; or
• Place all curses calls in a single “screen management” thread.
i. Sketch some example code to illustrate the first approach.

ii. Consider the second approach: how might the threads that
are calculating what needs to be updated communicate those
updates to the screen-management thread? Draw a blockdiagram that shows the architecture for this approach.

iii. List the advantages and disadvantages of each approach.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The first approach(Mutex guard) is used to prevent simultaneous execution of a critical section (a piece of code that accesses a shared resource) by multiple threads. In C++, std::mutex class can be used to protect shared data from concurrent access by more than one thread of execution. It is based on locking and unlocking mechanism. Once a mutex is locked, the currently executing thread will own the resource until it is unlocked. Which means that no other thread can execute any instructions until mutex unlocks the block of code surrounded by it.

Use of mutex to solve the synchronization problem:

  1. class Race_condition  
  2. {  
  3. public:  
  4.     std::mutex mutex;  
  5.     int n;  
  6.     Race_condition() :n(0) {}  
  7.     void increment() {  
  8.     mutex.lock();  
  9.     ++n;  
  10.     mutex.unlock();  
  11.     }  
  12. };  

Advantages of mutex:

1. Easy to implement: Mutexes are just simple locks that a thread obtains before entering its critical section, and then releases it.

2. Gurantee synchronization: Since only one thread is in its critical section at any given time, there are no race conditions and data remain consistent.

Disadvantages of mutex:

1. If a thread obtains a lock and goes to sleep, or is preempted, then the other thread may never be able to move forward. This will hold true until the thread handling lock will be scheduled again. It may lead to starvation.

2. Cannot be locked or unlocked from a different context than the one that acquired it.

3. Only one thread is allowed in the critical section at a time.

4. Normal implementation leads to busy-waiting which wastes CPU time.

Add a comment
Know the answer?
Add Answer to:
The curses display library is considered not to be “thread safe”. Two software architectures that will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help writing a well structured document using the below Agile Runbook - Our Overall Delivery Process How do we initiate a Project? Any project is a response to a pain point or desire expresse...

    Please help writing a well structured document using the below Agile Runbook - Our Overall Delivery Process How do we initiate a Project? Any project is a response to a pain point or desire expressed by either customers, internal stakeholders, employees, or regulatory authorities. In short, a project is a time bound and specific goal oriented task-system that is born out of an ask from any stakeholder. Project initiation is laying down a new project by defining its goals, objectives,...

  • Below is the information: It is important to understand the different leadership styles employed by nursing...

    Below is the information: It is important to understand the different leadership styles employed by nursing leaders in healthcare organizations and to understand their significance on nursing practice and patient outcomes, for better or for worse. Objective: Read the articles from Nursing Standard (PDF) and Bradley University (PDF). In -250 words, formulate an opinion on the following: 1. Reflect on an occasion where you experienced ineffective leadership (doesn't have to be in the hospital). What behaviors did they display? What...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

  • First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below...

    First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below Include each of the following in your answer (if applicable – explain in a paragraph) Research problem: what do you want to solve using Delphi? Sample: who will participate and why? (answer in 5 -10 sentences) Round one questionnaire: include 5 hypothetical questions you would like to ask Discuss: what are possible outcomes of the findings from your study? Hint: this is the conclusion....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT