Re: pemalloc in PHP_MINIT_FUNCTION segfaults on win (but not on linux)
| From: | Andrey Hristov | Date: | Tue, 13 Mar 2007 23:39:00 +0000 |
| Subject: | Re: pemalloc in PHP_MINIT_FUNCTION segfaults on win (but not on linux) | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-4624@lists.php.net to get a copy of this message | ||
Hi,
Holger Blasum wrote:
> Hello pecl-dev,
>
> executive summary: in php-5.2.0 (or 5.0.0), is it ok to do a pemalloc in
> the PHP_MINIT_FUNCTION? If not, what is the appropriate (minimalist) way
> to provide memory that is going to be shared globally among
> all threads/clients?
PHP's TSRM provides portable mutexes. Use MUTEX_T in conjunction with
- tsrm_mutex_alloc()
- tsrm_mutex_free()
- tsrm_mutex_lock()
- tsrm_mutex_unlock()
> slightly more verbose explanation: this is my PHP_MINIT_FUNCTION
> PHP_MINIT_FUNCTION(stack) {
> StackContext(s) = (STACK *)pemalloc(sizeof(STACK),1);
> return SUCCESS;
> } to have a globally shared stack. (To be shared among different
> threads/clients.)
>
> Much more detail (including full source of the toy 'stack' example) at
> http://www.blasum.net/holger/journal/20070312/
>
> (valgrinding it on linux gves me 'ERROR SUMMARY: 0 errors from 0
> contexts (suppressed: 29 from 2)', for the suppressed ones i have 25
> in libc5 and 4 in dl_relocate_object, so apparently not php-related)
>
> Many thanks in advance for any help (e.g.: is this generally the
> 'right way' of doing this? (I admit that I wanted to avoid resources
> because they seem thread-specific.) Did I make a subtle error or is it a
> win-specific thing?... )
>
HTH,
Andrey