-
-
Save JohnPeel/39afeac6491d264a0816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compiled successfully in 688 ms. | |
6036 was here... | |
5920 was here... | |
6108 was here... | |
4796 was here... | |
5684 was here... | |
180 was here... | |
5792 was here... | |
5472 was here... | |
5284 was here... | |
4216 was here... | |
Successfully executed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program new; | |
{$loadlib libthread} | |
var | |
x: string; | |
section: TCriticalSection; | |
procedure Test(Thread: TThread; Data: Pointer); native; | |
begin | |
section.Acquire(); | |
x := x + IntToStr(Thread.getThreadID()) + ' was here...'#13#10; | |
section.Release(); | |
end; | |
var | |
ThreadPool: array[0..9] of TThread; | |
I: LongInt; | |
begin | |
x := ''; | |
section.Init() | |
for I := 0 to 9 do | |
begin | |
ThreadPool[I].Init(Test, nil); | |
ThreadPool[I].Start() | |
end; | |
//Waiting... | |
for I := 0 to 9 do | |
begin | |
ThreadPool[I].WaitFor(); | |
ThreadPool[I].Free() | |
end; | |
section.Free(); | |
WriteLn(x); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment