Skip to content

Latest commit

 

History

History
39 lines (24 loc) · 1.52 KB

10.12.Sys.md

File metadata and controls

39 lines (24 loc) · 1.52 KB

10.12.Sys

The majority of Haxe targets are so-called "sys" targets. This means the targets have access to system APIs such as the filesystem, networking, threads, and more. The only non-sys targets supported by Haxe are Flash, JavaScript, and ActionScript 3, although JavaScript can support sys APIs when running under Node.js runtime.

  • See the sys package on the API documentation for more details on its classes.

10.12.1.Threading

A unified threading API is available on some sys targets. The compile-time define target.threaded is set when the API is available. The API allows very simple creation of threads from functions:

class Main {
  public static function main():Void {
    #if (target.threaded)
    sys.thread.Thread.create(() -> {
      while (true) {
        trace("other thread");
        Sys.sleep(1);
      }
    });
    Sys.sleep(3);
    #end
  }
}

All spawned threads are treated as daemon threads, meaning that the main thread will not wait for their completion.

Due to threads having access to a shared memory space with all the Haxe variables and objects, it is possible to run into issues due to deadlocks and race conditions. The standard library provides some core synchronization constructs in the sys.thread package.