Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP SegFault when using scheduler+custom thread

Comments in 'Plugin Development' started by L3m0nte4_, Dec 27, 2014.

  1. L3m0nte4_
    Offline

    L3m0nte4_ New Member

    Joined:
    Dec 25, 2014
    Posts:
    12
    Minecraft User:
    lem0ntea_
    In my plugin, plugin schedules process() repeating on every tick.

    PHP:
    public function process(){
            echo 
    "called\nhandlePacket()\n";
            
    $work false;
            if(
    $this->handlePacket()){
               
                
    $work true;
                while(
    $this->handlePacket());
            }
            echo 
    "pushInternalQueue()\n";
            
    $this->pushInternalQueue([chr(Info::SIGNAL_TICK)]);
            echo 
    "done tick\n";
        }
    and pushInternalQueue sends Info::SIGNAL_TICK(0xf0) to Internal thread, and My another thread gets that in Thread::run()

    PHP:
    public function run(){
            
    $this->logInfo("Thread started.");
            while(
    $this->shutdown === false){
                echo 
    "tick!()\n";
                if(
    strlen($buffer $this->readInternalQueue()) > 0){
                    echo 
    "switch!\n";
                    switch(
    ord($buffer{0})){
                        case 
    Info::SIGNAL_UPDATE:
                            break;
                           
                        case 
    Info::SIGNAL_SHUTDOWN:
                            
    $this->shutdown true;
                            break;
                           
                        case 
    Info::SIGNAL_TICK:
                            
    //TODO
                            
    break;
                    }
                }
                echo 
    "tickend!\n";
            }
            
    $this->logEmergency("Thread stopped!");
        }
    (Note: the two codes are executed in diffrent thread.)
    Buf if I create the Thread(second code) and registers tick schedule(first code), console prints like this:

    Code:
    tick!()
    tickend!
    tick!()
    tickend!
    tick!()
    tickend!
    tick!()
    tickend!
    called
    handlePacket()
    tick!()
    pushInternalQueue()
    tickend!
    tick!()
    tickend!
    tick!()
    tickend!
    tick!()
    tickend!
    tick!()
    tickend!
    tick!()
    tickend!
    tick!()
    tickend!
    tick!()
    tick!()
    tickend!
    tick!()
    tickend!
    tick!()
    pushInternalQueue() start
    tickend!
    tick!()
    pushInternalQueue() done
    done tick
    
    (Sorry for dirty echo function, but I had to debug where the trouble is...)
    It seems like when I send SIGNAL_TICK to another thread with threaded internalQueue custom thread crashes the server. If I don't register tick schedule to call process(), server doesn't print segfault and stop.

    Is this problem caused by internal pthreads extension bug? Or my mistake?
    Can threaded internalQueue contain array? (Raklib's internal/external queue contains only string, but I tried to contain an array for convenience)
  2. L3m0nte4_
    Offline

    L3m0nte4_ New Member

    Joined:
    Dec 25, 2014
    Posts:
    12
    Minecraft User:
    lem0ntea_
  3. L3m0nte4_
    Offline

    L3m0nte4_ New Member

    Joined:
    Dec 25, 2014
    Posts:
    12
    Minecraft User:
    lem0ntea_
    Eww, I found I overwritten the Threaded object to string, just forgot to use $this->internalQueue[] = $buffer; instead of $this->internalQueue = $buffer;
    PEMapModder and Falk like this.
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    :p
  5. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    However keep in mind that PHP Threads (pthreads) are unstable :)
    PEMapModder likes this.

Share This Page

Advertisement