2016-04-23 46 views
1

有沒有可能繼承包含文件和定義變量在pthread運行方法?我曾嘗試過PTHREADS_INHERIT_NONE,但似乎 無法正常工作。我們使用了下面的代碼。pthread不繼承定義者,幷包含文件

$domain_root='/home/user/abc'; 
define('DIR_FS_DOMAIN_ROOT', $domain_root); 
class NEWThread extends Thread{ 
    public function __construct() 
    { 

    } 
    public function run() 
    { 
     $this->html=DIR_FS_DOMAIN_ROOT; 
    } 
} 
$th=new NEWThread(PTHREADS_INHERIT_NONE); 
$th->start(); 
$th->join(); 
echo $th->html; 

回答

0

在錯誤的地方使用PTHREADS_INHERIT_NONE。它應該與啓動方法一起使用。

$domain_root='/home/user/abc'; 
define('DIR_FS_DOMAIN_ROOT', $domain_root); 
class NEWThread extends Thread{ 
    public function __construct(){ 
    } 
    public function run(){ 
    $this->html=DIR_FS_DOMAIN_ROOT; 
    } 
} 
$th=new NEWThread(); 
$th->start(PTHREADS_INHERIT_NONE); 
$th->join(); 
echo $th->html;