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

Explain structure, Explain Structure The Grammar for programming langua...

Explain Structure The Grammar for programming language is a formal description of Structure

Define memory management, Define memory management In multiprogramming ...

Define memory management In multiprogramming system the user part of memory should be further subdivided to accommodate multiple processes. The task of subdivision is carried o

Semantics for execution of rpcs, Q. Presume that a distributed system is su...

Q. Presume that a distributed system is susceptible to server failure. What mechanisms would be needed to guarantee the exactly once semantics for execution of RPCs? Ans

How virtual memory is implemented, How Virtual memory is implemented Vi...

How Virtual memory is implemented Virtual memory can be implemented along with Segmentation and Paging

Write xeyes on command line, Ask question #Minimum 100 words accepteWrite a...

Ask question #Minimum 100 words accepteWrite an xeyes command to display a window that is: ? SIZE: ¦ 400 pixels wide ¦ 300 pixels tall ? LOCATION: ¦ 100 pixels from the right edge

Explain how situation can be solved using active directory, Question: a...

Question: a) Windows Server 2003 has brought great enhancements the Server System as compared to the previous version. Write down short notes on the below listed enhancements.

Memory management, example of first fit best fit and worst fit

example of first fit best fit and worst fit

What is meant by the phrase thread-safe, The term thread-safe in computer p...

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

Describe the technique of packing, Describe the technique of packing. T...

Describe the technique of packing. The physical record size will not accurately match the length of the desired logical record and the Logical records may even differ in length

Thread, advantages and disadvantages of kernal level thread

advantages and disadvantages of kernal level thread

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