USER THREAD-MEMORY
VARIABLE EXTRA-MEM
0x4000  EXTRA-MEM !

: ALLOCATE-THREAD-MEMORY ( -- )
  USER-OFFS @ EXTRA-MEM @ CELL+ + 1 2 ['] calloc
  C-CALL DUP
  IF
     DUP CELL+ TlsIndex!
     THREAD-MEMORY !
     R> R@ TlsIndex@ CELL- ! >R
  ELSE
     -300 THROW
  THEN
;

: FREE-THREAD-MEMORY ( -- )
\ ���������� ��� �������� ������ ��� ��������
   THREAD-MEMORY @ DUP >R free DROP
;
USER R0
: POOL-INIT ( n -- )
  SP@  + CELL+ S0 !
  RP@ R0 !
  DECIMAL
  ATIB TO TIB
  0 TO SOURCE-ID
  0 TO SOURCE-ID-XT
  S-O TO CONTEXT FORTH DEFINITIONS
  POSTPONE [
  HANDLER 0!
  CURSTR 0!
  CURFILE 0!
\  INCLUDE-DEPTH 0!
  TRUE WARNING !
  12 C-SMUDGE !
\  ALIGN-BYTES-CONSTANT ALIGN-BYTES !
\  INIT-MACROOPT-LIGHT
;

: USER-INIT ( n -- )
  ALLOCATE-THREAD-MEMORY
  POOL-INIT
\  AT-THREAD-STARTING 
;

: USER-EXIT
\  AT-THREAD-FINISHING
  FREE-THREAD-MEMORY
;

: PLATFORM ( -- a u ) S" Linux" ;

