

  '========================
  'RUNNING MULTIPLE THREADS
  '========================

  library "kernel32.dll"
  sys   CreateThread (sys lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, *lpThreadId)
  dword WaitForMultipleObjects(sys nCount,*lpHandles, bWaitAll, dwMilliseconds)
  bool  CloseHandle(sys hObject)
  void  Sleep(sys dwMilliSeconds)
  library ""

  % INFINITE 0xFFFFFFFF  'Infinite timeout

  function RunAll(sys n,*funs)
  '==============================
  '
  sys  hThread[64], id[64], i
  '
  for i=1 to n
    hThread[i] =  CreateThread 0,0,funs[i],i,0,id[i]
  next
  '
  WaitForMultipleObjects n, hThread, 1, INFINITE
  '
  '
  for i=1 to n
    CloseHandle hThread[i]
  next
  '
  end function
  '
  'THREADS
  '=======
  '
  '
  string s[8]<=("String A:" cr,"string B:" cr,"string C:" cr)
  '
  '-------------------------------------------
  function ThreadA( sys n ) as sys external
  '===========================================
  finit
  sys i=65,j
  do
    s[n]+=chr(i)
    inc i
    sleep 1
    if i>90 then i=65 : inc j : if j=4 then exit do
  end do
  return 0
  end function 

  '-------------------------------------------
  function ThreadB( sys n ) as sys external
  '===========================================
  finit
  sys i=97,j
  do
    s[n]+=chr(i)
    inc i
    sleep 1
    if i>122 then i=97 : inc j : if j=4 then exit do
  end do
  return 0
  end function 

  '-------------------------------------------
  function ThreadC( sys n ) as sys external
  '===========================================
  finit
  sys i=48,j
  do
    s[n]+=chr(i)
    inc i
    sleep 1
    if i>57 then i=48 : inc j : if j=8 then exit do
  end do
  return 0
  end function 


  '====
  'TEST
  '====
  '
  sys threads[3]={@ThreadA, @ThreadB, @ThreadC}
  RunAll 3,threads
  print s[1] cr s[2] cr s[3] cr




