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

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. 

Posted Date: 6/29/2012 2:16:05 AM | Location : United States







Related Discussions:- What is meant by the phrase thread-safe, Assignment Help, Ask Question on What is meant by the phrase thread-safe, Get Answer, Expert's Help, What is meant by the phrase thread-safe Discussions

Write discussion on What is meant by the phrase thread-safe
Your posts are moderated
Related Questions
Question 1 Discuss the following with respect to Operating Systems: Operating System Components Operating System Services Question 2 Describe the theory behind Pagin

What are two differences among user-level threads and kernel-level threads? Under what circumstances is one type better than the other? (1) User-level threads are unknown by th

Hashed page tables A common approach for handling address spaces larger than 32 bits is to use a hashed page table. Every entry in the hash table having a linked list of elemen

fork and join syntax in java

Q. What is Multiprogramming? Multiprogramming When two or more programs are in memory at the same instance, sharing the processor is referred to multiprogramming opera

How is memory management done using linked lists?   Each one node of the l list will have 4 fields as follows 1-this tells whether it s a hole or a process 2-starting ad

Define Disadvantages of Top Down parsing of Backtracking The disadvantages of top down parsing of backtracking: (i)  Semantic actions cannot be carried out while making a pr

Explain the TlsGetValue (TLSindex) Function Executing this function will return the thread local storage data associated with this thread. The pointer returned will be the one

The primary financial objective of corporation is usually taken to be the maximization of shareholder wealth. Discuss:- i. Ways in which the shareholder of a company can encour

Q. Describe the three main architectural layers of Windows XP? Answer: (1) The HAL (Hardware Abstraction Layer) creates operating system portability by hiding hardware differ