Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does thread safe mean in a PHP context? [duplicate]

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?

like image 942
Yasser1984 Avatar asked Nov 30 '11 22:11

Yasser1984


Video Answer


1 Answers

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.

like image 191
alex Avatar answered Nov 14 '22 22:11

alex