tthread1.pp 542 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. program tthread1;
  2. {$mode objfpc}
  3. uses
  4. {$ifdef unix}
  5. cthreads,
  6. {$endif}
  7. Classes;
  8. type
  9. TTestThread = class(TThread)
  10. protected
  11. procedure Execute; override;
  12. public
  13. property ReturnValue;
  14. end;
  15. procedure TTestThread.Execute;
  16. var
  17. thrd: TThread;
  18. begin
  19. thrd := CurrentThread;
  20. if thrd <> Self then
  21. ReturnValue := 1
  22. else
  23. ReturnValue := 0;
  24. end;
  25. var
  26. t: TTestThread;
  27. begin
  28. t := TTestThread.Create(False);
  29. try
  30. t.WaitFor;
  31. ExitCode := t.ReturnValue;
  32. finally
  33. t.Free;
  34. end;
  35. Writeln(ExitCode);
  36. end.