That also implies then that if I create a handler for eg: an
external stream/file, and keep it as a singleton instance in the
extension, then it could be reasonably called by any number
of different threads.
There's a plan B though.
void foo(int bar) { }
foo() doesn't have room for trms_ls in its prototype so it just won't be
available inside the function right? Wrong. Zend exports TSRMLS_FETCH();
which can recover (through a slightly expensive process) the thread
appropriate value for tsrm_ls. Thus:
void foo(int bar TSRMLS_DC)
{
somefoo(bar TSRMLS_CC);
}
and
void foo(int bar)
{
TSRMLS_FETCH();
somefoo(bar TSRMLS_CC);
}
Are functionally identical.
ie: any resource callable from a php-extension must be
thread safe...
In order to work in all build environments? Yes.
Would that be a fair comment? (Means my single-threaded
data engine prototype is going to need a serious going over).
Technically, if you *know* that your php-extension will only ever be used in
a non-threaded environment (e.g. non-Win32, non-Apache2,
non-otherThreadedWebSAPI), then you can be "lazy" and not worry about thread
safety (or tsrm_ls in general). I would however *strongly recommend*
reworking your library for thread safety so that this problem doesn't become
an issue later on.
-Sara
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php