Interlacing of event handler execution

Discussion in 'Plugin Development' started by SaxSalute, Feb 11, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    SaxSalute

    I'm currently dealing with a bit of a data race issue in one of my plugins. Players are able to slip into lobbies by spamming pearls at the ground before dying. By adding print statements to my code I was able to see that the player death listener was being set off partway through the teleport listener. The listeners are in the same class and there's only one instance of the listener registered. I decided to use a static Object as a token by which to synchronize the methods. However, the execution of the two is still being alternated in such a way that this bug can occur. Is there a way that I can synchronize the execution of two of the listener methods to prevent this data race?
     
  2. Offline

    Konato_K

    @SaxSalute Listeners run in the main thread as far I know, if you want one to handle an event before another one (considering is the same event) use EventPriority
     
  3. Offline

    SaxSalute

    It's not the order that's the issue. The problem is that the teleport listener starts, then the death listener starts and finishes before the teleport listener finishes. I determined it's all in the main thread so that behavior isn't making sense to me.
     
  4. Offline

    mythbusterma

    @SaxSalute

    Which events are you using? Post your code. This sort of issue is not possible under normal circumstances.
     
    Rocoty likes this.
Thread Status:
Not open for further replies.

Share This Page