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 single-user systems, We have stressed the need for an operating sys...

We have stressed the need for an operating system to make efficient use of the computing hardware. When is it appropriate for the operating system to forsake this principle and to

Operating systems, Ask using a laballed diagram explaining the architecture...

Ask using a laballed diagram explaining the architecture of windows operating ststem

Rule a magnetic hard disk, Q. If magnetic hard disks eventually have the s...

Q. If magnetic hard disks eventually have the same cost per gigabyte as do tapes will tapes turn into obsolete or will they still be needed? Describe your answer. Answer: Tap

Explain lru page replacement in detail, LRU page replacement In least ...

LRU page replacement In least lately used page replacement algorithm we will replace that page that hasn't been used for the longest period of time. This is similar as an opti

Explain the resource ownership by platform, Explain the Resource Ownership ...

Explain the Resource Ownership by Platform Ownership of data items may further be complicated by concepts defined in certain operating systems. Each operating system defines "p

What is the hardware support required to implement paging, What is the hard...

What is the hardware support required to implement paging? Each operating system has its own techniques for storing page tables. The majority allocates a page table for each pr

Application of consumer behaviour, Q. Explain application of consumer behav...

Q. Explain application of consumer behaviour? Consumer behaviour is described as the dynamic interaction of affect and cognition and behaviour and the environment by human bein

Explain about threading issues, Explain about threading issues? The for...

Explain about threading issues? The fork and exec system calls In a multithreaded program of few UNIX systems have chosen to have two versions of fork, one that duplicates e

Define the properties of interactive operating system, Define the propertie...

Define the properties of Interactive operating system Interactive:- This system is composed of many short transactions where the results of the next transaction may be unpred

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