Page 1 of 1

QueueUserWorkItem - windows thread pool

Posted: Mon Dec 29, 2014 3:13 pm
by uweb
I found QueueUserWorkItem in a old thread in german forum.
It was a tip from Danilo.
May its usefull for somebody here.
Queues a work item to a worker thread in the thread pool.

Code: Select all

Import "kernel32.lib"
  QueueUserWorkItem(*threadFunction,*argument=0,Flags.l=0)
EndImport

Global x, y = 1000

Procedure t(value)
  If value = y : x = #True : EndIf
  a = Random($0FFFFFFF)*Random($0FFFFFFF)*Random($0FFFFFFF) ; do something
  ;Debug Str(value) + " - " + Str(x)
EndProcedure


x = 0
StartTime = ElapsedMilliseconds() 
Debug "Start " + Str(y) + " threads via CreateThread"
For i = 1 To y
  CreateThread(@t(), i)
Next
Repeat : Until x
Delay(y) ; time to end all
Debug ElapsedMilliseconds()-(StartTime+y)


x = 0
StartTime = ElapsedMilliseconds() 
Debug "Start " + Str(y) + " threads via QueueUserWorkItem"
For i = 1 To y
  QueueUserWorkItem(@t(),i)
Next
Repeat : Until x
Delay(y)
Debug ElapsedMilliseconds()-(StartTime+y)