Sorting algorithms/Sleep sort: Difference between revisions

Content added Content deleted
(→‎{{header|Perl}}: prepend pascal)
m (→‎{{header|Pascal}}: limit 4000)
Line 1,304: Line 1,304:


=={{header|Pascal}}==
=={{header|Pascal}}==
{{works with|Free Pascal}}
my limit under linux was 4000 threads nearly 2 GB.
<lang pascal>
<lang pascal>
program sleepsort;
program sleepsort;
Line 1,350: Line 1,352:
sleep(40*cft_count+1);
sleep(40*cft_count+1);
fi := Finished-1;
fi := Finished-1;
write(fi:5,cft_count:8,#13);
//write(fi:5,cft_count:8,#13);
InterLockedDecrement(Finished);
InterLockedDecrement(Finished);
SortIdx[fi]:= NativeUint(parameter);
SortIdx[fi]:= NativeUint(parameter);
Line 1,371: Line 1,373:
begin
begin
cft_ThreadHandle :=
cft_ThreadHandle :=
BeginThread(@TestRunThd, Pointer(j), cft_ThreadID,16384);
BeginThread(@TestRunThd, Pointer(j), cft_ThreadID,16384 {stacksize} );
If cft_ThreadHandle = 0 then break;
If cft_ThreadHandle = 0 then break;
end;
end;
Line 1,384: Line 1,386:
For j := 0 to UsedThreads-1 do
For j := 0 to UsedThreads-1 do
CloseThread(ThreadBlocks[j].cft_ThreadID);
CloseThread(ThreadBlocks[j].cft_ThreadID);

//output of sleep-sorted data
For j := UsedThreads-1 downto 1 do
For j := UsedThreads-1 downto 1 do
write(ThreadBlocks[SortIdx[j]].cft_count,',');
write(ThreadBlocks[SortIdx[j]].cft_count,',');
Line 1,410: Line 1,414:


real 0m3,164s</pre>
real 0m3,164s</pre>

=={{header|Perl}}==
=={{header|Perl}}==
Basically the C code.
Basically the C code.