Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "inherently thread-safe" mean?

I came across this line "some functions are inherently thread-safe, for example memcpy()"

Wikipedia defines "thread-safe" as:

A piece of code is thread-safe if it only manipulates shared data structures in a manner that guarantees safe execution by multiple threads at the same time.

OK. But what does inherently mean? Is it related to inheritance?

like image 241
Vikram Avatar asked Apr 07 '14 09:04

Vikram


People also ask

Which of the following is inherently thread-safe?

Answer: Since String is immutable in Java, it's inherently thread-safe. 2) Read-only or final variables in Java are also thread-safe in Java.

What does it mean if something is thread-safe?

Thread safety is a computer programming concept applicable to multi-threaded code. Thread-safe code only manipulates shared data structures in a manner that ensures that all threads behave properly and fulfill their design specifications without unintended interaction.

What does being thread-safe mean Java?

thread-safety or thread-safe code in Java refers to code that can safely be utilized or shared in concurrent or multi-threading environment and they will behave as expected.

Which attributes are inherently thread UN safe?

Class variables are not thread safe because all threads share the same method area, and the method area is where class variables are stored. This means that multiple threads can attempt to use the same class variables concurrently and so thread safety cannot be guaranteed.


1 Answers

It is not related to inheritance. It is an informal expression and means more like
"some functions are thread-safe by their nature". For example a function which does not
touch any shared values/state is thread safe anyway i.e. "is inherently thread-safe".

like image 154
peter.petrov Avatar answered Oct 08 '22 03:10

peter.petrov