In article <pgitvf$r6i$
1...@cherry.spenarnc.xs4all.nl>,
>>> >I tried to run it in a Linux Virtual machine. 16 cores 16 GB ram.
>>> >But that segfaults with lina8G. I will try with more ram.
>>> >
>>> >Is it possible to run the program on wina64?
Not even on wina32 when you asked the question.
>>>
>>> Programs are portable accross ciforth, except for availability of
>>> library functions.
I implemented THREAD-PET for wina 32bits , which amounts to adding
2 screens to the forth.lab library, see below.
Now r10par.frt (originally for lina 32/64) runs unaltered under wine
with the -s (scripting) option:
wine wina.exe -s r10par.frt -p 6 2,000,000,000
[Not only is 2G about the largest a 32 bit Forth can do, but the
answers is easy to remember: 98 2222 87 primes. ]
Tests with 20 threads on wine and a few threads on a one core
Celeron under Windows-XP all give correct results, but the speed is terrible.
<SNIP>
>I've done some work and I have come this far:
>
>\ Design issue for threads under MS-Windows
>\ If you start using MS handles, you're lost because it is
>\ impossible to know what happens.
>\ The only thing we can be sure about is that CreateThread
>\ passes control to a code address, and that that code can
>\ end by a ret instruction. Then cleanup will be matched to startup.
>\ So we do all our Forth stuff between a CALL and RET instruction
>\ and don't touch MS-Windows business.
>
This strategy worked after all. As long as no DLL calls are made
in the threads these two screens do the job.
\ ----------------------------------------------
( runthread ) CF: ?WI ?32
WANT ASSEMBLERi86-HIGH
MAX-USER @ DUP USER ME CELL+ MAX-USER !
CODE return RET, END-CODE \ Return via the stack
: EXIT-PET ME @ DSP! return ;
\ Run xt from thread to completion, remember handle .
: doit ME ! DUP 2 CELLS + @ CATCH DUP IF ERROR THEN
EXIT-PET ;
CODE runthread \ Run the thread passed via the MS-stack.
MOV, X| T| BX'| R| SP|
POP, R| AX| POP, R| AX|
MOV, X| T| SP'| BO| [AX] 0 B,
MOV, X| T| BP'| BO| [AX] 1 CELLS B,
PUSH, R| AX| PUSH, R| BX|
LEA, SI'| MEM| 'doit >PHA L, NEXT,
END-CODE TRIM
\ ----------------------------------------------
( THREAD-PET KILL-PET ) CF: ?WI ?32
WANT K32 CTA runthread
"CreateThread" 'K32 DLL-ADDRESS: _Create-Thread
"TerminateThread" 'K32 DLL-ADDRESS: _Terminate-Thread
_Terminate-Thread DROP _Create-Thread DROP
\ Start thread : thread-id .
: CREATE-THREAD CALL[ PARS @ 6 CELLS ERASE
'runthread >CFA @ PAR3 ( thr) PAR4 _Create-Thread CALL]
DUP ?ERRUR ;
\ Use space for "thread" / run xt in thread.
: THREAD-PET ALLOT CTA CREATE RSP@ SWAP RSP! R0 @ S0 @
ROT RSP! ( DSP) , ( TASK) , ( xt ) 0 , ( pid) 0 ,
DOES> >R R@ 2 CELLS + ! R@ CREATE-THREAD
R> 3 CELLS + ! ;
: KILL-PET >BODY 3 CELLS + @ \ Forced kill of thread .
CALL[ PAR1 0 PAR2 _Terminate-Thread CALL] ;
\ ----------------------------------------------
This is the text that succeeds, the usage can be
inspected by `` top '' or an equivalent MS-windows tool.
\ ----------------------------------------------
1000 THREAD-PET jan
VARIABLE aapje 0 aapje !
: testje 123456789 aapje ! ;
: loopie 123456789 aapje ! BEGIN AGAIN ;
.( expect 0 :) aapje ? CR
'testje jan
100 MS
.( expect 123.. :) aapje ? CR
0 aapje !
.( expect 0 :) aapje ? CR
'loopie jan
100 MS
.( expect 123.. :) aapje ? CR
.( expect 100% usage )
10000 MS
'jan KILL-PET
.( expect 0% usage )
\ -----------------------------
I have some one working on wina64 bits now.
The nice thing is of course a multithreading that is portable
accross 32 and 64 bits Linux and Windows.
P.S. Oops. doit is a terrible name, but at least that is copy
paste of working code.