tw38230.pp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. {$mode objfpc}
  2. uses
  3. {$ifdef unix}cthreads,{$endif} math, classes;
  4. type
  5. tmythread = class(tthread)
  6. constructor create; reintroduce;
  7. procedure execute; override;
  8. end;
  9. tmychildthread = class(tmythread)
  10. procedure execute; override;
  11. end;
  12. var
  13. e: TFPUException;
  14. expectedfpumask: tfpuexceptionmask;
  15. constructor tmythread.create;
  16. begin
  17. inherited create(true);
  18. end;
  19. procedure tmythread.execute;
  20. var
  21. e: TFPUException;
  22. begin
  23. write('thread: ');
  24. for e in GetExceptionMask do
  25. write(e,', ');
  26. writeln;
  27. if GetExceptionMask<>expectedfpumask then
  28. begin
  29. writeln(hexstr(cardinal(GetExceptionMask),8));
  30. writeln(hexstr(cardinal(expectedfpumask),8));
  31. halt(1);
  32. end;
  33. with tmychildthread.create do
  34. begin
  35. start;
  36. waitfor;
  37. free;
  38. SetExceptionMask([ExDenormalized]);
  39. // in case custom masks are not supported, get the actual new mask
  40. expectedfpumask:=GetExceptionMask;
  41. write('after setting ExDenormalized mask: ');
  42. for e in expectedfpumask do
  43. write(e,', ');
  44. writeln;
  45. end;
  46. end;
  47. procedure tmychildthread.execute;
  48. var
  49. e: TFPUException;
  50. begin
  51. write('child thread: ');
  52. for e in GetExceptionMask do
  53. write(e,', ');
  54. writeln;
  55. if GetExceptionMask<>expectedfpumask then
  56. halt(2);
  57. end;
  58. begin
  59. write('main: ');
  60. for e in GetExceptionMask do
  61. write(e,', ');
  62. writeln;
  63. expectedfpumask:=GetExceptionMask;
  64. with tmythread.create do
  65. begin
  66. start;
  67. waitfor;
  68. free;
  69. end;
  70. with tmythread.create do
  71. begin
  72. start;
  73. waitfor;
  74. free;
  75. end;
  76. end.