NativeThread.hx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package eval.vm;
  23. extern class NativeThread {
  24. /**
  25. Creates a new thread that executes function `f`.
  26. Exceptions caused while executing `f` are printed to stderr and are not
  27. propagated to the parent thread.
  28. **/
  29. function new(f:Void->Void):Void;
  30. /**
  31. Return the identifier of the given thread. A thread identifier is an integer
  32. that identifies uniquely the thread. It can be used to build data structures
  33. indexed by threads.
  34. **/
  35. function id():Int;
  36. /**
  37. Terminate prematurely the thread whose handle is given. This functionality is
  38. available only with bytecode-level threads.
  39. **/
  40. function kill():Int;
  41. /**
  42. Suspends the execution of the calling thread for `f` seconds. The other program
  43. threads continue to run during this time.
  44. **/
  45. static function delay(f:Float):Void;
  46. /**
  47. Terminate prematurely the currently executing thread.
  48. **/
  49. static function exit():Void;
  50. /**
  51. Suspends the execution of the calling thread until the thread `thread` has
  52. terminated.
  53. **/
  54. static function join(thread:NativeThread):Void;
  55. /**
  56. Return the thread currently executing.
  57. **/
  58. static function self():NativeThread;
  59. /**
  60. Re-schedule the calling thread without suspending it. This function can be used
  61. to give scheduling hints, telling the scheduler that now is a good time to switch
  62. to other threads.
  63. **/
  64. static function yield():Void;
  65. static function readMessage<T>(block:Bool):T;
  66. function sendMessage<T>(msg:T):Void;
  67. }