include "$\inc\minwin.inc"
include "$\inc\console.inc"

SetConsoleTitle "Threaded Console Input: 'q' to quit"

string sa 'shared input string
sys    ra 'shared input flag

function InputThread(sys p) as sys callback
===========================================
do
  if ra=1 then
    sa=rtrim input
    ra=2 'signal input available
  elseif ra=3 'quit
    exit do
  else
    sleep 20
  end if
end do
end function

sys thread
thread=CreateThread 0,0,@InputThread,0,0,0

sys c
ra=1 'ready for input
do
  c++ 'activity
  if ra=2 then
    if sa="q" then
      ra=3 'quit
      exit do
    end if
    print c " activity cycles" cr
    ra=1
  end if
  sleep 20
end do

sleep 100
CloseHandle thread
'waitkey


