From:             
Operating system: Windows
PHP version:      Irrelevant
Package:          Other web server
Bug Type:         Bug
Bug description:ts_free_thread() frees only temporary in multiple parallel 
threads

Description:
------------
I created my own php sapi 1 year ago and it was only single threaded.

Now I tried to make it multi-threaded by using TSRM.



I got 1 thread starting up and shutting down the TSRM and my module and
many other threads executing requests. You can take a look at this abstract
example here:



DWORD WINAPI test_thread(void*)

{

    TSRMLS_FETCH() // a lot of memory is allocated here

    

    // execute the request (just core functions written here)

    php_request_startup(TSRMLS_C);

    php_execute_script(fh, TSRMLS_C);

    php_request_shutdown(TSRMLS_C);

        

    ts_free_thread(); // I tried to free the memory allocated through
TSRMLS_FETCH() here

}



int main()

{

    tsrm_startup(1, 1, 0, NULL);

    sapi_startup(&my_php_sapi);

    php_module_startup(&my_php_sapi, NULL, 0);

    sapi_activate(TSRMLS_C);

        

    // start 25 threads running "test_thread()" here

        

    // call module/sapi shutdown functions

    tsrm_shutdown(); // all memory gets freed here

}



The request threads work fine but I noticed that all the copies allocated
through TSRMLS_FETCH() last in the memory until tsrm_shutdown() gets
executed. So I browsed the web and found that ts_free_thread() should solve
it. But now here's the problem:

When I'm executing only 1 request thread at a time, everything works fine
and ts_free_thread() frees all resources. But when I run multiple threads
at the same time the memory gets up and down until all threads finished.
But after all threads exited the memory grows up enormous.



This is what happens:

- start 25 threads                -- memory: ~25.000 k

- threads finish one by one       -- memory: ~25.000 k --> ~4.000 k

- all threads finished            -- memory: ~60.000 k



I was using php 5.2.9 and now tried the same with the latest stable 5.3.3
release but the problem still resists.



I couldn't really locate the problem yet.

Expected result:
----------------
memory stays at ~4.000 k when all threads finish

Actual result:
--------------
memory grows suddenly about more that 100 percent

-- 
Edit bug report at http://bugs.php.net/bug.php?id=53430&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=53430&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=53430&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=53430&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=53430&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=53430&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=53430&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=53430&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=53430&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=53430&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=53430&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=53430&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=53430&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=53430&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=53430&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53430&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53430&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=53430&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=53430&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=53430&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=53430&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=53430&r=mysqlcfg

Reply via email to