Currently, to access module globals in TS mode, a global resource array is used. That array contains globals from all the threads and per thread globals are identified by the thread key. The thread key is passed to every function requiring access to the globals. Or, it has to be fetched on demand. Consequently
This RFC bases on https://wiki.php.net/rfc/tls , however I don't mention it under the “First Published” position. While the key points are the same, the patch and the meaning undergone some changes. Still teh base RFC contains a lot of useful info about cross platform compatibility and various TLS implementations, so I would say it is useful to briefly read through it as well.
The technique of passing thread id explicitly should be removed where possible. Ideally, one global thread specific variable should be used to hold the thread key (while it's not possible exactly the way on every platform, see the implementation details).
The current patch focuses on stability and code quality improvement more than on performance. Whereby the latest tests show that the patched version is at least as fast as the mainstream.
The current implementation is done by the following scheme
As also described in the base RFC, the main difficulty to make this process cross platform is that not every compiler (for instance Visual Studio) support sharing a thread specific variable between shared objects. For that reason, the function call to tsrm_get_ls_cache() is needed at least once per thread in order to work with the thread specific resources. Such an operation is needed to be done within every binary unit.
In the patch, almost any macros accessing globals, like EG, CG, etc. are ported to use a local TSRMLS pointer which is static to that binary unit (i.e. shared extension or SAPI bin/dll/so). For that three steps are required
These are also the steps required to port an extension/SAPI to be compatible with the patch. The porting was done step by step and the static TSRMLS cache is only enabled when ZEND_ENABLE_STATIC_TSRMLS_CACHE macro is defined from the config.* script. Otherwise the method with dynamic cache fetching per tsrm_get_ls_cache() is used.
Currently all the ocurrencies with TSRMLS_* macros evaluate to empty but left at their places, so then the diff shows the real change done. They are going to be removed once the RFC is accepted and before it was merged
PHP7
Threading capable SAPIs may need to be reworked. Currently it regards only to Apache mpm_worker and mpm_winnt. See implemtation details.
See implementation details.
A potential incompatibility to not widely used operating systems can be introduced. Any Unix (like) OS using pthreads or other threads implementation supported by the TSRM layer, or any x86/x64 Windows system, are supported. That covers good 99% of the target OSes (please read the base RFC for more details).
The patch from the base RFC used an offset mechanism instead of the array indexing to access globals. That part wasn't ported in the current patch as it has caused too much issues. This however should be still done as using offsets would speedup the data access.
Userland is not affected, the change is internals only.
The vote starts on 12/10/2014 at 21:00 CET and ends on 12/17/2014 at 21:00 CET. 50%+1 majority required.
Keep this updated with features that were discussed on the mail lists.*/