Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between thread safe and thread compatible?

What is the difference between thread safe and thread compatible?

  • What thread compatible mean?
  • What is use cases for thread compatible?

UPD: I have found this definition in the grpc documentation of StreamObserver.

Also, I have found the link to Characterizing thread safety but its still not clear for me.

If a method requires to be in synchronize block, that means that is just threaded unsafe?

like image 592
mkUltra Avatar asked Oct 09 '18 06:10

mkUltra


People also ask

What is the meaning of thread-safe?

In the simplest of terms threadsafe means that it is safe to be accessed from multiple threads. When you are using multiple threads in a program and they are each attempting to access a common data structure or location in memory several bad things can happen.

What's the difference between a thread-safe and a thread unsafe function?

Thread safety A threadsafe function protects shared resources from concurrent access by locks. Thread safety concerns only the implementation of a function and does not affect its external interface. The use of global data is thread-unsafe.

How do you know if something is thread-safe?

To test if the combination of two methods, a and b, is thread-safe, call them from two different threads. Put the complete test in a while loop iterating over all thread interleavings with the help from the class AllInterleavings from vmlens. Test if the result is either an after b or b after a.

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.

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

Thread Safety works by creating a local storage copy in each thread so that the data will not collide with another thread. Non-thread-safe: It does not check the safety of the threads which makes it faster to run but at the same time, it becomes more unstable and crashes very frequently. It refers to a single thread only builds.

What is the difference between threadsafe and synchronized?

I'm little bit confused between Threadsafe and synchronized. Thread safe means that a method or class instance can be used by multiple threads at the same time without any problems occurring. Where as Synchronized means only one thread can operate at single time. So how they are related to each other?

What is thread safety in C++?

Thread Safety works by creating a local storage copy in each thread so that the data will not collide with another thread. Non-thread-safe: It does not check the safety of the threads which makes it faster to run but at the same time, it becomes more unstable and crashes very frequently.

What does thread compatible mean?

Thread compatible means not thread safe, but not thread hostile - so to satisfy thread safety, the user must perform synchronization themselves 1 But the definition of correctness varies a little... Java In Theory And In Practice defines this according to the class's specification.


Video Answer


2 Answers

Thread safe means that an object can be used by many threads concurrently and still be correct 1

Thread hostile means that the object does something (mutates static state, thread local storage etc.) that prevents it from being thread safe.

Thread compatible means not thread safe, but not thread hostile - so to satisfy thread safety, the user must perform synchronization themselves


1 But the definition of correctness varies a little...

Java In Theory And In Practice defines this according to the class's specification.

Geoff Romer at Google and Wikipedia define this as simply lack of data races.

I usually hope this to mean no crashes, deadlocks or other surprises.

like image 164
Peter Wishart Avatar answered Oct 21 '22 16:10

Peter Wishart


thread safe means that the object is safe to use concurrently in multiple threads, it is implemented by java self; although thread compatiple is not thread safe, it still can be safe to use concurrently when you surround some synchronization code in your non-thread-safe code or have a wrapper object where it is thread safe.Namely that you shoud implement is by yourself.

like image 22
sasa Avatar answered Oct 21 '22 17:10

sasa