Thread Strategy

Discussion in 'Plugin Development' started by Raphfrk, Jan 2, 2011.

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


    In the info thread, it is mentioned that threads will be handled differently with this API. (in order to allow the servers to be multi-threaded.)

    Does each plugin end up in its own thread, or will it be necessary to worry about syncing between different hook calls?

    For example, if the the server is handling two players in different threads, how will the onBlockCreate (or whatever) events be handled. Will each thread call the plugin hooks, and so the plugin will have to sync between hook calls?
  2. Offline


    I think each hook is its own thread and all plugins are executed sequentially.
  3. Offline

    Herr Riz

    That's pretty exciting. It will be pretty difficult for plugins to cause lag, then, won't it?
  4. Offline


    Plugins will still be able to cause lag.
    • If every hook is its own thread, all I have to do is write a slow player move handler and all moving players will be affected.
    • If every hook call gets its own thread, then with enough players and plugins the server will be swamped with too many threads and start thrashing.
    • If every hook call is delegated to a thread pool, then one poorly implemented hook handler anywhere can lead to thread pool exhaustion, stopping all further hook calls from executing.
    • Regardless of threading strategy, if a plugin author misuses a synchronization construct, the entire server can be forced to inadvertently singlethread as each hook call is forced to queue up behind a protected section.
    Additionally, with more multithreading in the plugin API, the chance of deadlock increases dramatically. Judging by the sophistication of some of the plugin devs asking for help in the hMod forums, not everybody writing plugins will be an expert at writing safe, efficient multithreaded code.
    legendblade likes this.
  5. Offline


    But i'm sure there will be something implemented to prevent this sort of thing from happening, easier said than done :p
  6. Offline


    Related to this, will there be a server queue method like,

    server.addToServerQueue( Runnable )
  7. Offline


    That would be a comittee of people approving the proper coding of a plugin (which, i assume, many plugins will fail at)
    DoggyCodeâ„¢ likes this.
  8. Offline


    Added a suggestion related to this.

    The suggestion is that there would be a WORLD_SYNC_EVENT that occurs at regular intervals (ideally once every server tick).

    I think something like this is an important feature. Otherwise thread based plugins have no way to call API functions from any additional threads created.
Thread Status:
Not open for further replies.

Share This Page