What is thread-safe and non-thread safe?

Source: Internet
Author: User
Tags vc9

What is thread-safe and non-thread safe?

Thread safety is the case that there is no data inconsistency in a multithreaded environment, and there is a risk of inconsistent data for non-thread safety.

Thread safety controls the read and write of resources to ensure data consistency, in other words, increases the overhead of the system. As a result, efficiency in a single-threaded environment is less efficient than non-threading, but if data is correlated between threads, the read-write order needs to be guaranteed, with thread-safe mode

This is primarily for Web server, in a Windows environment, if you are using a Web server that is Apchae or the following version of IIS 7, you should choose a thread-safe installation file, and if you use fast-cgi mode, you can choose non-thread-safe because The Web sever itself guarantees thread safety.
And, of course, the compiler used by the binaries compile: Vc9 (VS series) VC6 (GCC)

As said upstairs, for Web server, some Web server processing application requests is multi-threaded rather than multi-process approach, threading method because it involves the sharing register and memory, so it is easy to error, At this point the program needs to spend some extra time dealing with data consistency in the register, which guarantees thread safety.
So whether the use of thread safety mainly depends on your Web server PHP request processing method, if it is multithreaded processing, then choose thread-Safe, otherwise choose non-thread-safe, such as the upstairs said Fast-cgi way can choose non-thread-safe

First of all, in the literal sense, none-thread safe is non-thread-safe, do not thread security at execution time, thread safe is threaded, thread security is performed, to prevent new requirements to start a new thread of CGI The execution method exhausts the system resources.

Let's look at two ways of executing PHP: ISAPI and fastcgi. FastCGI execution is performed in a single thread, so there is no need for thread security checks, and removing thread security checks can improve execution efficiency, so if PHP is executed in FastCGI (whether with IIS 6 or IIS 7), it is recommended to download, execute Non-thread Safe php (php Two files are packaged in two ways: MSI, zip, download the zip kit). Thread safety checks are prepared for the ISAPI way of PHP, because there are many PHP modules that are not thread-safe, so you need to use the thread safe PHP.

Speaking of which, you should know how to choose which version of PHP. None-thread safe or Thread safe, which would you choose?

The current version of PHP under Windows is already 5.3.6, now the version of Windows can be downloaded in PHP official PHP for Windows (http://windows.php.net/download/), the same version of the download is VC9 x86 Non thread safe, VC9 x86 thread safe, VC6 x86 Non thread safe, VC6 x86 thread safe, etc. four versions. So what's the difference between these versions?

The version of VC9 was compiled with Legacy VS 2008, and the VC6 version was compiled with Legacy VS6.

If you are using iis+php under Windows, you need to download the VC9 version.
If you are using apache+php under Windows, you need to download the VC6 version.

Non thread safe refers to non-thread safety, thread safe refers to threading security.

If you are using ISAPI to run PHP, you must use the thread safe version, while running PHP in fastcgi mode, there is no need to use thread security, with none thread safe (NTS, non-thread-safe) Version to better improve efficiency.

How to judge:

Through Phpinfo (); Look at the thread Safety item in it, this project is to see if it is thread safe, if yes: enabled, generally it should be TS version, otherwise it is version nts.

from:http://blog.csdn.net/aoyoo111/article/details/19021295

What is thread-safe and non-thread safe?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.