@@ -169,6 +169,9 @@ static void process_pool_onWorkerStart(ProcessPool *pool, Worker *worker) {
169169zend_update_property_long (swoole_process_pool_ce,SW_Z8_OBJ_P (zobject),ZEND_STRL (" workerPid" ),getpid ());
170170zend_update_property_long (swoole_process_pool_ce,SW_Z8_OBJ_P (zobject),ZEND_STRL (" workerId" ), worker->id );
171171
172+ swoole_set_process_type (SW_PROCESS_WORKER);
173+ SwooleG.enable_coroutine = pp->enable_coroutine ;
174+
172175if (pp->onWorkerStart ) {
173176 zval args[2 ];
174177 args[0 ] = *zobject;
@@ -259,6 +262,9 @@ static void process_pool_onStart(ProcessPool *pool) {
259262zend_update_property_long (swoole_process_pool_ce,SW_Z8_OBJ_P (zobject),ZEND_STRL (" master_pid" ),getpid ());
260263zend_update_property_bool (swoole_process_pool_ce,SW_Z8_OBJ_P (zobject),ZEND_STRL (" running" ),true );
261264
265+ swoole_set_process_type (SW_PROCESS_MASTER);
266+ SwooleG.enable_coroutine =false ;
267+
262268if (pp->onStart ==nullptr ) {
263269return ;
264270 }
@@ -312,6 +318,10 @@ static void process_pool_signal_handler(int sig) {
312318 }
313319}
314320
321+ ProcessPool *sw_process_pool () {
322+ return current_pool;
323+ }
324+
315325static PHP_METHOD (swoole_process_pool, __construct) {
316326 zval *zobject = ZEND_THIS;
317327 zend_long worker_num;
@@ -321,15 +331,31 @@ static PHP_METHOD(swoole_process_pool, __construct) {
321331
322332// only cli env
323333if (!SWOOLE_G (cli)) {
334+ swoole_set_last_error (SW_ERROR_OPERATION_NOT_SUPPORT);
324335zend_throw_error (NULL ," %s can only be used in PHP CLI mode" ,SW_Z_OBJCE_NAME_VAL_P (zobject));
325336 RETURN_FALSE;
326337 }
327338
328339if (sw_server ()) {
329- zend_throw_error (NULL ," %s cannot use in server process" ,SW_Z_OBJCE_NAME_VAL_P (zobject));
340+ swoole_set_last_error (SW_ERROR_OPERATION_NOT_SUPPORT);
341+ zend_throw_error (NULL ," cannot create server and process pool instances simultaneously" );
330342 RETURN_FALSE;
331343 }
332344
345+ if (sw_process_pool ()) {
346+ swoole_set_last_error (SW_ERROR_OPERATION_NOT_SUPPORT);
347+ zend_throw_error (NULL ," A process pool instance has already been created and cannot be created again" );
348+ RETURN_FALSE;
349+ }
350+
351+ #ifdef SW_THREAD
352+ if (!tsrm_is_main_thread ()) {
353+ swoole_set_last_error (SW_ERROR_OPERATION_NOT_SUPPORT);
354+ zend_throw_exception_ex (swoole_exception_ce, -1 ," This operation is only allowed in the main thread" );
355+ RETURN_FALSE;
356+ }
357+ #endif
358+
333359if (zend_parse_parameters_throw (ZEND_NUM_ARGS ()," l|llb" , &worker_num, &ipc_type, &msgq_key, &enable_coroutine) ==
334360 FAILURE) {
335361 RETURN_FALSE;
@@ -390,6 +416,10 @@ static PHP_METHOD(swoole_process_pool, set) {
390416if (php_swoole_array_get_value (vht," max_package_size" , ztmp)) {
391417 pool->set_max_packet_size (php_swoole_parse_to_size (ztmp));
392418 }
419+ if (php_swoole_array_get_value (vht," max_wait_time" , ztmp)) {
420+ zend_long v =zval_get_long (ztmp);
421+ pool->max_wait_time =SW_MAX (0 ,SW_MIN (v, UINT32_MAX));
422+ }
393423}
394424
395425static PHP_METHOD (swoole_process_pool, on) {