' Thread Sync — THREAD STATUS, CLOSE with sync
#COMPILE EXE
#DIM ALL

FUNCTION Worker(BYVAL dummy AS LONG) AS LONG
    LOCAL i AS LONG
    FOR i = 1 TO 5
        PRINT "Worker iteration " + STR$(i)
        SLEEP 100
    NEXT i
    FUNCTION = 0
END FUNCTION

FUNCTION PBMAIN() AS LONG
    LOCAL hThread  AS LONG
    LOCAL status  AS LONG
    THREAD CREATE Worker(0) TO hThread
    THREAD STATUS hThread TO status
    PRINT "Thread status: " + STR$(status)
    THREAD CLOSE hThread
    PRINT "Thread closed"
    FUNCTION = 0
END FUNCTION
