Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between thread-aware and thread-safe?

What is the difference between thread-awareness and thread-safety?

like image 745
Philip Avatar asked Dec 05 '11 06:12

Philip


People also ask

What is thread aware?

Thread Aware At any given time, at most one thread can be active on the object. The object is aware of the threads around it and protects itself from the threads by putting all the threads in a queue.

What is difference between thread-safe and non thread-safe?

A thread-safe version should be used if you install PHP as an Apache module in a worker MPM (multi-processing model) or other environment where multiple PHP threads run concurrently - simply put, any CGI/FastCGI build of PHP does not require thread safety.

What is called thread-safe?

A [portion of code] is thread-safe if it behaves correctly when accessed from multiple threads, regardless of the scheduling or interleaving of the execution of those threads by the runtime environment, and with no additional synchronization or other coordination on the part of the calling code.

What is the difference between thread-safe and non thread-safe in Java?

When multiple threads are working on the same data, and the value of our data is changing, that scenario is not thread-safe and we will get inconsistent results. When a thread is already working on an object and preventing another thread on working on the same object, this process is called Thread-Safety.


1 Answers

courtesy http://sreekalyan.blogspot.com/2007/01/thread-safe-and-thread-aware.html

Thread Aware At any given time, at most one thread can be active on the object. The object is aware of the threads around it and protects itself from the threads by putting all the threads in a queue. Since there can be only a single thread active on the object at any given time, the object will always preserve its state. There will not be any synchronization problems.

Thread safe: At a given time, multiple threads can be active on the object. The object knows how to deal with them. It has properly synchronized access to its shared resources. It can preserve its state data in this multi-threaded environment (i.e. it will not fall into intermediate and/or indeterminate states). It is safe to use this object in a multi-threaded environment.

Using an object that is neither thread-aware nor thread-safe may result in getting incorrect and random data and mysterious exceptions (due to trying to access the object when it is being used by a thread and is in an unstable, in-between state at the instant of access of the second thread).

like image 167
FosterZ Avatar answered Nov 16 '22 00:11

FosterZ