There are a million on-line, but writing your own is more fun.
Code: Select all
const NUM_THREAD = 8
const RUN_TIME = 60.0
'some floating point and memory action
sub burn(id as integer, runTime as double)
dim as double ptr pArray = callocate(1024 * 1024, sizeof(double))
if pArray <> 0 then
print "start"; id
dim as double tEnd = timer + runTime
while timer < tEnd
for i as integer = 0 to 1024 * 1024 - 1
pArray[i] = i ^ (sqr(i) + sin(i) + tan(i))
next
wend
deallocate(pArray)
else
print "callocate fail"
end if
end sub
dim pThread(NUM_THREAD - 1) as any ptr
print "run for about " & RUN_TIME & " seconds"
for i as integer = 0 to ubound(pThread)
pThread(i) = threadcall burn(i, RUN_TIME)
sleep 100
next
for i as integer = 0 to ubound(pThread)
threadwait pThread(i)
print "end"; i
sleep 1
next
print "All done"