What is meant by the phrase thread-safe, Operating System

Assignment Help:

The term thread-safe in computer programming describes that routine or portion of the program that may be called from multiple programming threads without uncalled for interactions between the threads. (The instance of the program which runs on behalf of some user or process is called Thread) The importance of thread safety to object oriented programming language is that it gives built-in support for threads. By the use of thread-safe routines, the risk of one thread interfering and modifing data elements of another thread gets eliminated by circumventing future/potential data race situations with coordinated access to shared data. 

It is possible to ensure that a routine is thread-safe by ensuring that synchronized algorithms are used by the concurrent threads use that cooperate with each other and limiting the shared object's  address to a single thread each time an unsynchronized algorithm is active. 

Web Reference: by Douglas C. Schmidt, 2005

                        Strategized Locking, Thread-safe Interface, and Scoped Locking                       

 

                    Present your own fully documented and tested programming example illustrating the use of locks to govern access to critical sections.

 

std::atomic inspct = 0;

int counts = 0;

Lock lck; ----

 

    if (lck.TryEnter()) {

        inspct.store(/* get thread id */, memory_order_relaxed);

        return true;

    }

    return false;

} 

bool TryEnter() {

    if (inspct.load(memory_order_relaxed) == /* get thread id */) {

        counts += 1;

        return true;

    } 

void Exit() {

    if (counts != 0) {

        counts -= 1;

        return;

    }

    inspct.store(0, memory_order_relaxed);

    lck.Exit();

}

The atomic variables do not cause data races, even in the most relaxed states. Here the variable is declared as atomic, There is no reason why the compiler would assume that the write can’t be implimented by other threads. 


Related Discussions:- What is meant by the phrase thread-safe

We can view an operating system as a resource allocator, We can view an ope...

We can view an operating system as a resource allocator. Explain. We can outlook an operating system as a resource allocator. A computer system has Many resources (software and

Multiprogramming, explain how response time are reduced by allowing time sh...

explain how response time are reduced by allowing time sharing on top of multiprogramming

Which are the different states of a process, Which are the different states...

Which are the different states of a process?   Different status of a process is: New: When the process is created. Running: When instructions are executed. Wait

Is it essential to bind a real-time thread to an lwp, Q. Presume an operati...

Q. Presume an operating system maps user-level threads to the kernel using the many-to-many model and the mapping is done through LWPs. Additionally the system allows developers to

What is demand paging, What is Demand paging? Virtual memory is commonl...

What is Demand paging? Virtual memory is commonly executed by demand paging. In demand paging, the pager brings only those essential pages into memory instead of swapping in a

Write about critical regions and monitors, Write about critical regions and...

Write about critical regions and monitors. Critical region definition Monitor definition Implementation of the conditional-region construct Syntax of monitor Monito

What are the requirements for a swapper to work, The swapper work s on t...

The swapper work s on the biggest scheduling priority. Initially it will look for any sleeping process, if not get then it will see for the ready-to-run process for swapping. Bu

Thread pools, Another solution then would be to keep a pool of threads. Whe...

Another solution then would be to keep a pool of threads. Whenever a new task arrives, the system would simply get a thread from pool and set that thread to work on the given task.

Write a short note on the linux file systems, Question: (a) Red Hat Li...

Question: (a) Red Hat Linux is distributed under the Open Source agreement. Explain what you understand by Open Source distribution system. (b) Write a short note on the L

Copy on write in virtual memory, how copy on write on pages when many proc...

how copy on write on pages when many process works at a same time?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd