What does thread safety mean in the context of PHP?

Possible duplicate:
What is thread safe or unsafe thread in PHP

What does it mean when something is or is not thread safe?

For example, setlocale () in PHP is not thread safe:

Locale information is maintained for each process, not for a thread. If you use PHP on an API with a multi-threaded server, such as IIS or Apache on Windows, you may encounter sudden changes in the locale settings of the running script, although the script itself never called Setlocale (). This is due to other scripts working in different threads of the same process at the same time, changing with setlocale ().

http://php.net/manual/en/function.setlocale.php

What does this mean? Is it good that something is thread safe or not?

Under what conditions do you need thread-safe or non-thread-safe solutions to your problems?

+6
source share
1 answer

A safe thread is good, it means that while there may be several parallel threads, they talk to each other safely, which will not have race conditions, concurrency problems, etc.

Thread safety is a computer programming concept applicable in the context of multithreaded programs. A piece of code is thread-safe if it only manages common data structures in a thread-safe way that ensures that multiple threads can safely execute at the same time. There are various strategies for creating thread-safe data structures.

Source

+4
source

Source: https://habr.com/ru/post/902798/


All Articles