6

Possible Duplicate:
What is thread safe or non thread safe in PHP

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

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

The locale information is maintained per process, not per thread. If you are running PHP on a multithreaded server API like IIS or Apache on Windows, you may experience sudden changes in locale settings while a script is running, though the script itself never called setlocale(). This happens due to other scripts running in different threads of the same process at the same time, changing the process-wide locale using setlocale().

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

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

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


  • Did you read that part where it explains that it pertains to certain webserver setups only? It's not something you can choose or use. And setlocale is a good example of potential side-effects. (Except that it actually works per-thread on recent Windows versions.) - mario

1 답변


4

Thread safe is a good thing, it means whilst there may be multiple concurrent threads, they are talking to each other in a safe way that won't have race conditions, concurrency issues, etc.

Thread safety is a computer programming concept applicable in the context of multi-threaded programs. A piece of code is thread-safe if it only manipulates shared data structures in a thread-safe manner, which enables safe execution by multiple threads at the same time. There are various strategies for making thread-safe data structures.

Source.

Linked


Related

Latest