Ok, had a slight play with it again..

I did eventually find the perl code for threading although without an 
lxr server it's pretty much impossible to decipher all the macros they 
use..

The reality is I'm waving in the dark a bit - I've got a bit of spare 
time to play with it, but not really that sure whats going on all the 
time ;)

Working on the premise of thread creation starting another interpreter..
php compiled with --enable-experimental-zts, & debug. the code below 
manages to fire up the thread and run it.. - although it segfaults the 
main process after doing it.

This is a little supprising - I expected it to be the otherway round - 
as the logic kind of said that the new threads 'enviroment' (eg. vars) 
would not be initiated properly and it would fail.. , which could be the 
zval used in the callback causing issues..

The code for this stuff is pretty simple at the moment.. - so i'ts down 
the bottom..

As I said - if you can think of what needs doing, I've got a bit of time 
to play with it - although a little direction/hints do help..

regards
alan



void phpthreads_create(void *ptr) {
        zval *myretval; 
         
        void  **args = *(void ***) &ptr;
        zval *callback;    
        TSRMLS_FETCH();

        php_request_startup(TSRMLS_C); 
        callback           =  *(zval **) args[0] ;
        EG(class_table)    =  *(HashTable **) args[1] ;
        EG(function_table) =  *(HashTable **) args[2] ;
        
        if (!call_user_function( EG(function_table), NULL, callback,  myretval, 0, 
NULL TSRMLS_CC ))  { 
                zend_error(E_ERROR, "Problem Starting thread with callback");
                fflush(stdout);
        }
/* runs this perfectly!*/
        ts_free_thread( );
        
}
/* {{{ proto string phpthreads_thread(string function)
   Return a string to confirm that the module is compiled in */
PHP_FUNCTION(phpthreads_create)
{
        void **args[2];  
        zval *callback;
        pthread_t thread;
        phpthreads_flag = 1;
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callback) == 
FAILURE) {
                return;
        }
          
        args[0] = (void *)  &callback;
        args[1] = (void *)  &EG(class_table);
        args[2] = (void *)  &EG(function_table);
        
        
        pthread_create( &thread, NULL, (void *) phpthreads_create, (void*) &args);
      
        printf("DONE CREATING THREAD\n"); fflush(stdout);
        /* segfaults a little bit after this gets echoed */
        RETURN_TRUE;
}



>>>      
>>>
>>Ouch.  While it's an interesting way to deal with the issue, I think 
>>this will be way too slow, and maintenance will be hard (keeping up with 
>>changes in the real zend_execute, and zend engine in general).  As in a 
>>couple other responses, the way this needs to be implemented has been 
>>hashed out, largely based on how the same problem is solved in Perl 
>>(there is a remarkable amount of simularity between PHP and Perl at some 
>>levels).  If you're interested, lets talk.
>>
>>Shane
>>
>>
>>-- 
>>PHP Development Mailing List <http://www.php.net/>
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>    
>>
>
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Health - Feel better, live better
>http://health.yahoo.com
>
>  
>




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

Reply via email to