phpthreads - hints anyone...
| From: | Alan Knowles | Date: | Wed, 31 Jul 2002 08:57:11 +0000 |
| Subject: | phpthreads - hints anyone... | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-86362@lists.php.net to get a copy of this message | ||
Im looking at adding threading to php, (for the cgi/cli stuff)..
The story so far:
I've created an extension which diverts all zend_execute calls into the extension -> phpthreads_execute.
this function is a copy of zend_execute with a few modifications
- to copy & restore things like EG(active_symbol_table);
- to malloc lock and unlock the execute loop and release on each opcode.
I've started testing the phpthreads_create($callback); - it appears to work ok, execept it segfaults on completion.. - trying to reduce refcounts somewhere.
The fireup code looks something like this..
void phpthreads_create(void *ptr) {
zval myretval;
zval *callback = (zval *) ptr;
if (!call_user_function( EG(function_table), NULL, callback, &myretval, 0, NULL TSRMLS_CC )) {
zend_error(E_ERROR, "Problem Starting thread with callback");
}
pthread_exit(NULL);
}
/* {{{ proto string phpthreads_thread(string function)
Return a string to confirm that the module is compiled in */
PHP_FUNCTION(phpthreads_create)
{
zval *callback;
pthread_t thread;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callback) == FAILURE) {
return;
}
pthread_create( &thread, NULL, (void *) phpthreads_create, (void*) callback);
RETURN_TRUE;
}
and the backtrace of the simple threaded test looks like this..
0x08128f08 in _zval_ptr_dtor (zval_ptr=0x81b5ce8) at /usr/src/php/php4/Zend/zend_execute_API.c:275
275 (*zval_ptr)->refcount--;(gdb) bt #0 0x08128f08 in _zval_ptr_dtor (zval_ptr=0x81b5ce8) at /usr/src/php/php4/Zend/zend_execute_API.c:275 #1 0x424ceba2 in ?? () #2 0x424c7c92 in ?? () #3 0x08130588 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/src/php/php4/Zend/zend.c:810 #4 0x08110abd in php_execute_script (primary_file=0x40006c71) at /usr/src/php/php4/main/main.c:1398 #5 0x08110138 in php_module_shutdown () at /usr/src/php/php4/main/main.c:1058 #6 0x2e325f43 in ?? () does anyone want to suggest what might be missing - is it worth putting this into pecl - and does someone what to lend a hand?? regards alan