Bless You! It still segfaults all over the place (which is
    another story), but that particular call_user_function() now
    works, thanks :) and happy easter egg searching ;)

    - Markus

On Sun, Mar 31, 2002 at 01:11:27PM +0300, Zeev Suraski wrote : 
> At 20:59 30/03/2002, Markus Fischer wrote:
> >    Yes, exactly.
> 
> Ok, in that case, by default this won't work 'very nicely' with PHP 
> (because it's not very standard), but you should be able to get it to work 
> relatively easily.
> 
> The problem:
> 
> All of PHP's resources (globals, memory management, resource lists, 
> basically everything) are locked to a specific thread.  If you use all of 
> the standard macros (TSRMLS_FETCH(), TSRMLS_DC, etc.) then your code lives 
> entirely within the thread in which it's running, and cannot access 
> anything from other threads.
> 
> 
> The solution:
> 
> If you need to manipulate resources of another thread, you can do so, but 
> you have to do a bit of hacking on your own.
> 
> 1.  When you register the callback, you have to remember which thread you'd 
> want to interface with when the callback is called.  You can obtain the 
> thread id by using tsrm_thread_id():
> THREAD_T thread_id = tsrm_thread_id();
> 
> You have to store this information in a place which would be later 
> accessible from the callback.
> 
> 2.  inside the callback, don't use TSRMLS_FETCH().  Instead, use the 
> following line of code:
> 
> void ***tsrm_ls = (void ***) ts_resource_ex(0, &thread_id);
> 
> 3.  It's important to remember that there are some things that you must not 
> do inside your callback, due to mutual exclusion problems.  For instance, 
> doing any 'writes' to the resource lists, or even the memory manager - is 
> likely to cause a crash due to race conditions with the thread that owns 
> these resources.  As long as you limit yourself to read-only data, it 
> should be fine (even though I don't think we ever made sure that the data 
> structures are safe for reading while another thread writes to them).
> 
> That's about all I can tell you, other than good luck, and don't do it 
> unless you really have to :)
> 
> Zeev
> 
> 
> -- 
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php

-- 
Please always Cc to me when replying to me on the lists.
GnuPG Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
"Mind if I MFH ?" "What QA did you do on it?" "the usual?" "ah... none :)"

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to