Another version by Carles:
- Code: Select all Expand view
function Main()
local n
local aThreads := {}
Aadd( aThreads, hb_threadStart( @Slow() ) )
for n = 1 to 10
Aadd( aThreads, hb_threadStart( @ReadWeb() ) )
next
nThreads := len( aThreads )
while ( j := hb_threadWait( aThreads, 0.1, .T.) ) <> nThreads
? 'Executed => ' , j
end
? 'Executed All => ', nThreads
hb_threadWaitForAll()
InKey( 1 )
return nil
function Slow()
inkey(3)
? 'Thread: ', hb_threadId(), 'Slow Done'
retu nil
function ReadWeb()
local hCurl, cBuffer := ""
local cUrl := "http://www.modharbour.org/modharbour_samples/info.prg"
curl_global_init()
if ! empty( hCurl := curl_easy_init() )
curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
if curl_easy_perform( hCurl ) == 0
uValue := curl_easy_dl_buff_get( hCurl )
? 'Thread: ', hb_threadId(), 'Get: ' , len( uValue)
endif
endif
curl_global_cleanup()
return nil