pthreads - code thoughts....

From: Date: Wed, 05 Sep 2001 07:59:57 +0000
Subject: pthreads - code thoughts....
Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-42@lists.php.net to get a copy of this message
Hi, After playing with php-gtk a bit further, it became obvious that the lack of pthreads support is a serious problem. - the simple example was, creating a tree that browsed the filesystem. when loaded, it scans 2 levels of directories. and when opened it then scans the levels below this. If done without threads, the GUI freezes for quite a time on loading large directories. using threads (in python) it is possible to make this work nicely... Below is a _NON_WORKING_ attempt at adding thread support to the pcntl module.. I would have posted to php-dev, but Im not sure it will get much attention...... (especially as it doesnt work!) anyway thoughts would be appreciated... - like 'the concept is broken....' etc. (code below) regards alan --------------------------------- 2 functions in pcntl.c in the ext/pcntl folder (it also needs modifications to php_pcntl.h... PHP_FUNCTION(pcntl_thread_create) { zval **handle,*call_name,*retval; char *func_name; pthread_t tid; pcntl_threadParm_t *threadParm; PCNTL_LS_FETCH(); if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE) { WRONG_PARAM_COUNT; } /* Special long value case for SIG_DFL and SIG_IGN */ /* if (Z_TYPE_PP(handle)==IS_LONG) { if (Z_LVAL_PP(handle)!= (long) SIG_DFL && Z_LVAL_PP(handle) != (long) SIG_IGN) { php_error(E_WARNING, "Invalid value for handle argument specifEied in %s", get_active_function_name()); } if (php_signal(Z_LVAL_PP(signo), (Sigfunc *) Z_LVAL_PP(handle))==SIG_ERR) { php_error(E_WARNING, "Error assigning singal in %s", get_active_function_name()); RETURN_FALSE; } RETURN_TRUE; } */ if (Z_TYPE_PP(handle)!=IS_STRING) { php_error(E_WARNING, "Invalid type specified for handle argument in %s", get_active_function_name()); RETURN_FALSE; } convert_to_string_ex(handle); /* Just in case */ if (!zend_is_callable(*handle, 0, &func_name)) { php_error(E_WARNING, "%s: %s is not a callable function name error", get_active_function_name(), func_name); efree(func_name); RETURN_FALSE; } MAKE_STD_ZVAL(call_name); MAKE_STD_ZVAL(retval); ZVAL_STRING(call_name, func_name, 1); threadParm = (pcntl_threadParm_t *)malloc(sizeof(threadParm)); threadParm->function_table= EG(function_table); threadParm->object_pp=NULL; threadParm->function_name=call_name; threadParm->retval_ptr=retval; threadParm->param_count=0; threadParm->params= NULL; pthread_create(&tid, NULL, pcntl_call_user_function, threadParm); RETURN_TRUE; } void *pcntl_call_user_function(void *parm) { pcntl_threadParm_t *p = (pcntl_threadParm_t *)parm; HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, int param_count, zval *params[]); call_user_function(p->function_table, p->object_pp, p->function_name, p->retval_ptr, p->param_count, &p->params); }

« previous php.gtk.general (#42) next »