Thread.hx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C)2005-2018 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. /**
  24. Experimental Thread API.
  25. Note that the debugger does not properly support threads at the moment.
  26. **/
  27. extern class Thread {
  28. /**
  29. Creates a new thread that executes function `f`.
  30. Exceptions caused while executing `f` are printed to stderr and are not
  31. propagated to the parent thread.
  32. **/
  33. function new(f:Void -> Void):Void;
  34. /**
  35. Return the identifier of the given thread. A thread identifier is an integer
  36. that identifies uniquely the thread. It can be used to build data structures
  37. indexed by threads.
  38. **/
  39. function id():Int;
  40. /**
  41. Terminate prematurely the thread whose handle is given. This functionality is
  42. available only with bytecode-level threads.
  43. **/
  44. function kill():Int;
  45. /**
  46. Suspends the execution of the calling thread for `f` seconds. The other program
  47. threads continue to run during this time.
  48. **/
  49. static function delay(f:Float):Void;
  50. /**
  51. Terminate prematurely the currently executing thread.
  52. **/
  53. static function exit():Void;
  54. /**
  55. Suspends the execution of the calling thread until the thread `thread` has
  56. terminated.
  57. **/
  58. static function join(thread:Thread):Void;
  59. /**
  60. Return the thread currently executing.
  61. **/
  62. static function self():Thread;
  63. /**
  64. Re-schedule the calling thread without suspending it. This function can be used
  65. to give scheduling hints, telling the scheduler that now is a good time to switch
  66. to other threads.
  67. **/
  68. static function yield():Void;
  69. }