Re: [PHP-DEV] Thread safety failure in EG(function_table)?

2002-08-26 Thread Michael Sisolak

> I believe that I can reproduce a thread safety failure in
init_executor
> (as called from the ISAPI sapi).  I have a PHP script page that loads
> the stylesheet as a PHP page - thus causing two almost simultaneous
> page loads.  I assume that if in init_executor() directly after
> "EG(function_table) = CG(function_table);" I dump out any
non-internal
> functions in the function_table I shouldn't find any (as no script
page
> has been loaded yet in that thread).  That's how it works when my
main
> page loads, but when the second page load happens the functions from
> the first page show up in the function_table for the second!  Once
one
> of the threads releases it's local functions, the other still
believes
> they are valid and tries to release them also creating quite a mess.

I believe I have tracked this down to an issue in the threading model
of ISAPI applications vs. what the thread safe PHP is expecting.  I've
followed up in the thread "ISAPI Crash Debugging Notes".

Michael Sisolak
[EMAIL PROTECTED]

__
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

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




[PHP-DEV] Thread safety failure in EG(function_table)?

2002-08-26 Thread Michael Sisolak

I believe that I can reproduce a thread safety failure in init_executor
(as called from the ISAPI sapi).  I have a PHP script page that loads
the stylesheet as a PHP page - thus causing two almost simultaneous
page loads.  I assume that if in init_executor() directly after
"EG(function_table) = CG(function_table);" I dump out any non-internal
functions in the function_table I shouldn't find any (as no script page
has been loaded yet in that thread).  That's how it works when my main
page loads, but when the second page load happens the functions from
the first page show up in the function_table for the second!  Once one
of the threads releases it's local functions, the other still believes
they are valid and tries to release them also creating quite a mess.

Is there any legitimate way this could happen?  I'm pretty much at the
end of my ability to debug much deeper into the Zend Engine code and
still be able to understand what's going on, but this looks really odd
to me.

Michael Sisolak
[EMAIL PROTECTED]

__
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

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




Re: [PHP-DEV] Thread safety & global strings

2002-04-12 Thread brad lafountain


--- Marcus Boerger <[EMAIL PROTECTED]> wrote:
> Correct me if i am wrong:
> We have a macros that garantees thread safety for module globals TSRMG.
> But if we use this on strings or structures that is not thread safe because
> then the lock only occurs for copying the pointer. But another thread could
> change the global value what results in efree of the former copied pointer.
> 
> If i am correct we would need:
> a) to generate an error if TSRMG is used on a string
> b) a function that allows to do a thread safe copy operation with the string.
> OR
> we make TSRMG do this and all current TSRMG calls with strings have
> to explicitly call free for the copy.

 From what i understand the "other thread" will have its own local copy of the
global space. so on  a free it will free its own copy. Its global per thread
(httpd). And if you want a true global you need to use some kinda shared
memory.

 - Brad

__
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

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




[PHP-DEV] Thread safety & global strings

2002-04-12 Thread Marcus Boerger

Correct me if i am wrong:
We have a macros that garantees thread safety for module globals TSRMG.
But if we use this on strings or structures that is not thread safe because
then the lock only occurs for copying the pointer. But another thread could
change the global value what results in efree of the former copied pointer.

If i am correct we would need:
a) to generate an error if TSRMG is used on a string
b) a function that allows to do a thread safe copy operation with the string.
OR
we make TSRMG do this and all current TSRMG calls with strings have
to explicitly call free for the copy.

marcus



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




Re: [PHP-DEV] thread safety for binding issues

2002-03-31 Thread Markus Fischer

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 
> 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 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] thread safety for binding issues

2002-03-30 Thread Zeev Suraski

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 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] thread safety for binding issues

2002-03-30 Thread Markus Fischer

Yes, exactly.

On Sun, Mar 31, 2002 at 12:48:04AM +0300, Zeev Suraski wrote : 
> Markus - is that what you're talking about..?
> 
> Zeev
> 
> At 20:37 30/03/2002, Shane Caraveo wrote:
> >My understanding from Markus' original email was that the library he is 
> >using calls back into php on a different thread than that which he called 
> >it with.
> >
> >Shane

-- 
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 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] thread safety for binding issues

2002-03-30 Thread Zeev Suraski

Markus - is that what you're talking about..?

Zeev

At 20:37 30/03/2002, Shane Caraveo wrote:
>My understanding from Markus' original email was that the library he is 
>using calls back into php on a different thread than that which he called 
>it with.
>
>Shane


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




Re: [PHP-DEV] thread safety for binding issues

2002-03-30 Thread Shane Caraveo

My understanding from Markus' original email was that the library he is 
using calls back into php on a different thread than that which he 
called it with.

Shane

Zeev Suraski wrote:
> Get MT'd?  What do you mean by that?  We have no plans to make PHP a 
> multithreaded application at any time in the future, but I'm not exactly 
> sure why it matters to you..?
> 
> Zeev
> 
> At 17:16 30/03/2002, Markus Fischer wrote:
> 
>> Yes, thanks for the answer.
>>
>> I think the problem is just that I mixed up two different
>> things (thread-safety vs. multi-threaded). Err .. any idea
>> if/when PHP itself will get MTed ? :)
>>
>> - Markus
>>
>> On Sat, Mar 30, 2002 at 09:14:56AM +0200, Zeev Suraski wrote :
>> > It should work, it's using exactly the same thread safe code as the one
>> > under Windows...
>> >
>> > Zeev
>> >
>> > At 14:14 29/03/2002, Markus Fischer wrote:
>> > >Hi,
>> > >
>> > >how much thread-safe is PHP on linux when compiled with
>> > >--enable-experimental-zts ? When I a set up a callback
>> > >handler for a 3rd library which uses threads and in this (C)
>> > >callback I call call_user_function() (to provide custom
>> > >callbacks) -> bang , I get a segfault. Should it work and I'm
>> > >doing something stupid or is this some limitation? Hints?
>> > >
>> > >- Markus
>> > >
>> > >--
>> > >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 
>> > >To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>> >
>> > --
>> > PHP Development Mailing List 
>> > 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 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] thread safety for binding issues

2002-03-30 Thread Zeev Suraski

Get MT'd?  What do you mean by that?  We have no plans to make PHP a 
multithreaded application at any time in the future, but I'm not exactly 
sure why it matters to you..?

Zeev

At 17:16 30/03/2002, Markus Fischer wrote:
> Yes, thanks for the answer.
>
> I think the problem is just that I mixed up two different
> things (thread-safety vs. multi-threaded). Err .. any idea
> if/when PHP itself will get MTed ? :)
>
> - Markus
>
>On Sat, Mar 30, 2002 at 09:14:56AM +0200, Zeev Suraski wrote :
> > It should work, it's using exactly the same thread safe code as the one
> > under Windows...
> >
> > Zeev
> >
> > At 14:14 29/03/2002, Markus Fischer wrote:
> > >Hi,
> > >
> > >how much thread-safe is PHP on linux when compiled with
> > >--enable-experimental-zts ? When I a set up a callback
> > >handler for a 3rd library which uses threads and in this (C)
> > >callback I call call_user_function() (to provide custom
> > >callbacks) -> bang , I get a segfault. Should it work and I'm
> > >doing something stupid or is this some limitation? Hints?
> > >
> > >- Markus
> > >
> > >--
> > >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 
> > >To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> > --
> > PHP Development Mailing List 
> > 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 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] thread safety for binding issues

2002-03-30 Thread Markus Fischer

Yes, thanks for the answer.

I think the problem is just that I mixed up two different
things (thread-safety vs. multi-threaded). Err .. any idea
if/when PHP itself will get MTed ? :)

- Markus

On Sat, Mar 30, 2002 at 09:14:56AM +0200, Zeev Suraski wrote : 
> It should work, it's using exactly the same thread safe code as the one 
> under Windows...
> 
> Zeev
> 
> At 14:14 29/03/2002, Markus Fischer wrote:
> >Hi,
> >
> >how much thread-safe is PHP on linux when compiled with
> >--enable-experimental-zts ? When I a set up a callback
> >handler for a 3rd library which uses threads and in this (C)
> >callback I call call_user_function() (to provide custom
> >callbacks) -> bang , I get a segfault. Should it work and I'm
> >doing something stupid or is this some limitation? Hints?
> >
> >- Markus
> >
> >--
> >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 
> >To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> -- 
> PHP Development Mailing List 
> 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 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] thread safety for binding issues

2002-03-29 Thread Zeev Suraski

It should work, it's using exactly the same thread safe code as the one 
under Windows...

Zeev

At 14:14 29/03/2002, Markus Fischer wrote:
> Hi,
>
> how much thread-safe is PHP on linux when compiled with
> --enable-experimental-zts ? When I a set up a callback
> handler for a 3rd library which uses threads and in this (C)
> callback I call call_user_function() (to provide custom
> callbacks) -> bang , I get a segfault. Should it work and I'm
> doing something stupid or is this some limitation? Hints?
>
> - Markus
>
>--
>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 
>To unsubscribe, visit: http://www.php.net/unsub.php


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




Re: [PHP-DEV] thread safety for binding issues

2002-03-29 Thread Shane Caraveo

Markus Fischer wrote:
> On Fri, Mar 29, 2002 at 09:14:46AM -0800, Shane Caraveo wrote : 
> 
>>Markus Fischer wrote:
>>
>>>   Hi,
>>>
>>>   how much thread-safe is PHP on linux when compiled with
>>>   --enable-experimental-zts ? When I a set up a callback
>>>   handler for a 3rd library which uses threads and in this (C)
>>>   callback I call call_user_function() (to provide custom
>>>   callbacks) -> bang , I get a segfault. Should it work and I'm
>>>   doing something stupid or is this some limitation? Hints?
>>>
>>>   - Markus
>>>
>>
>>PHP is thread safe, not multi-threaded.  ie. scripts cannot be 
>>multi-threaded.  You will have to somehow proxy the data back to the 
>>original calling thread for your library to work.
> 
> 
> Ah, understood. So, the short answer would be it was by own
> stupidity ;-)
> 
> About proxying the data .. you don't happen to have some more
> description or resource how to accomplish this before I try
> to reinvent the wheel ? thanks.
> 
> - Markus
> 


You'll probably be able to get away with using condition variables, but 
it's too much to describe, and I haven't done much pthreads stuff.  You 
could get the o'reilly pthreads book for reference, or dig around for 
exampls on the net.

Shane



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




Re: [PHP-DEV] thread safety for binding issues

2002-03-29 Thread Markus Fischer

On Fri, Mar 29, 2002 at 09:14:46AM -0800, Shane Caraveo wrote : 
> Markus Fischer wrote:
> >Hi,
> >
> >how much thread-safe is PHP on linux when compiled with
> >--enable-experimental-zts ? When I a set up a callback
> >handler for a 3rd library which uses threads and in this (C)
> >callback I call call_user_function() (to provide custom
> >callbacks) -> bang , I get a segfault. Should it work and I'm
> >doing something stupid or is this some limitation? Hints?
> >
> >- Markus
> >
> 
> PHP is thread safe, not multi-threaded.  ie. scripts cannot be 
> multi-threaded.  You will have to somehow proxy the data back to the 
> original calling thread for your library to work.

Ah, understood. So, the short answer would be it was by own
stupidity ;-)

About proxying the data .. you don't happen to have some more
description or resource how to accomplish this before I try
to reinvent the wheel ? thanks.

- Markus

-- 
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 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] thread safety for binding issues

2002-03-29 Thread Shane Caraveo

Markus Fischer wrote:
> Hi,
> 
> how much thread-safe is PHP on linux when compiled with
> --enable-experimental-zts ? When I a set up a callback
> handler for a 3rd library which uses threads and in this (C)
> callback I call call_user_function() (to provide custom
> callbacks) -> bang , I get a segfault. Should it work and I'm
> doing something stupid or is this some limitation? Hints?
> 
> - Markus
> 

PHP is thread safe, not multi-threaded.  ie. scripts cannot be 
multi-threaded.  You will have to somehow proxy the data back to the 
original calling thread for your library to work.

Shane


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




[PHP-DEV] thread safety for binding issues

2002-03-29 Thread Markus Fischer

Hi,

how much thread-safe is PHP on linux when compiled with
--enable-experimental-zts ? When I a set up a callback
handler for a 3rd library which uses threads and in this (C)
callback I call call_user_function() (to provide custom
callbacks) -> bang , I get a segfault. Should it work and I'm
doing something stupid or is this some limitation? Hints?

- Markus

-- 
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 
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DEV] thread safety

2001-07-28 Thread Phil Driscoll

Zeev

If the thread safety stuff you've just committed might fiz the ISAPI 
problems, and you want some testing doing, please shout out.

Cheers
-- 
Phil Driscoll

-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]