Category : OS/2 Files
Archive   : FORTH039.ZIP
Filename : THREADS.4TH

 
Output of file : THREADS.4TH contained in archive : FORTH039.ZIP
\ THREADS.4TH - Thread creation under Forth/2 03/18/93
\ Copyright (c) 1993,1994 BLUE STAR SYSTEMS
\
\ These are some preliminary words to run threads under Forth/2 using
\ the OS/2 function CreateThread. Any output they do shows up in the
\ Forth/2 screen, but the output is harmless.
\
\ You can THREAD just about any word which operates independently and
\ does not require any stack parameters.
\
\ Warning: The thread does not start immediately, so be carefull of any
\ variables used to pass parameters to the new thread.
\
\ i.e. 1 alarm 2 alarm 10 alarm
\
\ will PROBABLY not result in the correct results, but rather all
\ three alarms going off in 10 seconds

decimal

variable ThreadInfo \ Information to be passed to thread, USER area
4 allot \ and execution address of thread

variable ThreadID
variable ThreadArg \ Allot parameter space after this
8192 constant ThreadStackSize
variable ThreadStack ThreadStackSize allot

: sleep ( seconds -- ) 1000 * MS ;

: StartThread ( code_addr -- )
ThreadInfo CELL+ ! 'USER @ ThreadInfo !
ThreadInfo ThreadArg !
ThreadStackSize
0 \ Flags: 0=Start now, 1=Start suspended
ThreadArg
['] ThreadProc
ThreadID SYS$CREATETHREAD
SYSCALL
6 DROPS ;

: KillThread ( pid -- ) SYS$KillThread SYSCALL 2drop ;

\ THREAD Usage: THREAD starts running as a separate thread

: THREAD State @ 0= If
' StartThread
Else
' Postpone Literal
Postpone StartThread
Then
; IMMEDIATE

\ Examples

: Bunny 5 sleep ." It keeps going, and going..."
50 0 do 2 sleep cr ." and going, and going..."
loop ;

variable TimeLength

: Timer ( -- ) TimeLength @ sleep ." It's time! " ;

: Alarm ( secs -- ) TimeLength ! Thread Timer ;

\ Try THREAD bunny or 10 Alarm Do a bunch of them!



  3 Responses to “Category : OS/2 Files
Archive   : FORTH039.ZIP
Filename : THREADS.4TH

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/