线程安全在 PHP 上下文中意味着什么? [英] What does thread safe mean in a PHP context?

查看:28
本文介绍了线程安全在 PHP 上下文中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
PHP 中什么是线程安全或非线程安全

某些东西是或不是线程安全的意味着什么?

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

例如,PHP 中的 setlocale() 不是线程安全的:

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

区域设置信息是按进程维护的,而不是按线程维护的.如果您正在多线程服务器 API(如 IIS 或 Apache)上运行 PHP在 Windows 上,您可能会遇到区域设置的突然变化,同时脚本正在运行,尽管脚本本身从未调用过设置区域设置().这是由于其他脚本运行在不同的同一进程的线程同时改变使用 setlocale() 的进程范围的语言环境.

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?

推荐答案

线程安全是一件好事,这意味着虽然可能有多个并发线程,但它们以一种不会发生竞争的安全方式相互通信条件、并发问题等

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.

来源.

这篇关于线程安全在 PHP 上下文中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆