Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #56622
| From | albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Why does the location of PAD move around? |
| Date | 2017-04-03 04:37 +0200 |
| Organization | A poorly-installed InterNetNews site |
| Message-ID | <obscho$3is$1@cherry.spenarnc.xs4all.nl> (permalink) |
| References | <20170401210719.376d37f4@_> <87o9we5mc8.fsf@nightsong.com> <0719e78c-1196-4465-b0a6-a604f3f73b96@googlegroups.com> <87h9265los.fsf@nightsong.com> |
In article <87h9265los.fsf@nightsong.com>,
Paul Rubin <no.email@nospam.invalid> wrote:
>Julian Fondren <julian.fondren@gmail.com> writes:
>>> I'm presuming the tasks all have the same HERE but maybe that's wrong.
>> Yes. that's wrong.
>
>Hmm, ok. Does that mean each task has its own wordlist and dictionary
>area that threads to a parent dictionary?
>
>For some reason I thought Forth's extremely lightweight tasking meant
>task memory of just the two stacks and a few saved registers. Task
>locals would come from the main heap. I got this impression from
>looking at the eForth tasker on Bill Muench's site.
>
>Is there any documentation I can find about a traditional Forth
>multitasker? The full sized Forths these days tend to use OS threads.
>Brad Rodriguez's articles are tantalizing but not very detailed about
>this subject.
It may look not detailed but there is not much to Forth multi-tasking,
actually.
There is some commonality between traditional and preemptive
multi tasking.
The following 4 screens taken from ciforth contain both:
one common screen for subdividing the memory of the mother task,
one screen if you want preemptive multitasking
two screens if you want cooperative multitasking
cooperative is longer because it does the bookkeeping that the
OS does for you in the preemptive case.
It is also more general. The preemptive screen contains LI?
which means that it can only be loaded on a linux system,
32 or 64 bit. An MS-Windows version would look nothing like it.
This code is tricky. For preemptive the central point is the
NR_clone system call. For cooperative it is the PAUSE-COT
command.
For the cooperative code keep in mind that in ciforth the only
pseudoregister to switch is the return stack. The data stack pointer
was stored on the return stack and the user variables are
coupled to the return stack pointer. The interpreter pointer
is incremented as usual, executing code even if that code
is switching to another task.
So bottom line, it is small but contains a lot of sharp edges
and debugging is a bitch. Before trying to understand this
code one must read the ciforth manual about the internals,
especially the memory layout.
-----------------------------------------
( CTA aux_for_threads ) \ AvdH B6jan23
\ Fails unless kernel prepared for threads
WANT TASK-SIZE
TASK-SIZE 4 / CONSTANT _TASK/4
\ Return the USERAREA of a new task, aligned.
: new-u0 DP @ _TASK/4 1- OR 1+ TASK-SIZE + _TASK/4 - ;
\ Clone the task area to a area of ``TASK-SIZE'' leave TASK
: CTA U0 @ new-u0 2DUP MAX-USER @ CELLS MOVE
2DUP SWAP - ( offset) SWAP 5 0 DO 2DUP I CELLS + +! LOOP
NIP NIP DUP _TASK/4 + DP ! 1 CELLS - ;
\
-----------------------------------------
( THREAD-PET KILL-PET PAUSE-PET ) CF: ?LI \ B5dec2
"CTA" WANTED "-syscalls-" WANTED HEX
\ Exit a thread. Indeed this is exit().
: EXIT-PET 0 _ _ __NR_exit XOS ;
\ Do a preemptive pause. ( abuse MS )
: PAUSE-PET 1 MS ;
\ Create a thread with dictionary SPACE. Execute XT in thread.
: THREAD-PET ALLOT CTA CREATE RSP@ SWAP RSP! R0 @ S0 @
ROT RSP! 2 CELLS - ( DSP) , ( TASK) , ( pid) 0 ,
DOES> DUP @ >R SWAP OVER CELL+ @ R@ 2! ( clone S: tp,xt)
100 R> _ __NR_clone XOS DUP IF
( Mother) DUP ?ERRUR SWAP 2 CELLS + ! ELSE
( Child) DROP RSP! CATCH DUP IF ERROR THEN EXIT-PET THEN ;
\ Kill a THREAD-PET , preemptively. Throw errors.
: KILL-PET >BODY 2 CELLS + @ 9 _ __NR_kill XOS ?ERRUR ;
DECIMAL
-----------------------------------------
( TASK-TABLE NEXT-TASK PAUSE-COT) HEX \ AvdH B5nov24
"BAG" WANTED
100 BAG TASK-TABLE VARIABLE TASK-POINTER
: THIS TASK-POINTER @ ;
\ Make first task current.
: SET-FIRST-TASK TASK-TABLE CELL+ TASK-POINTER ! ;
\ Add running task and make it current.
TASK-TABLE !BAG _ TASK-TABLE BAG+! SET-FIRST-TASK
\ Switch to next task, only administration.
: NEXT-TASK THIS CELL+ TASK-POINTER !
THIS TASK-TABLE @ = IF SET-FIRST-TASK THEN ;
\ Switch from current task to next one.
: PAUSE-COT
DSP@ >R RSP@ THIS ! NEXT-TASK THIS @ RSP! R> DSP! ;
-----------------------------------------
( EXIT-COT THREAD-COT ) HEX \ AvdH B5dec2
"TASK-TABLE" WANTED "CTA" WANTED "BAG-" WANTED
\ Exit: remove current task, then chain to first one.
: EXIT-COT THIS TASK-TABLE BAG-
SET-FIRST-TASK THIS @ RSP! R> DSP! ;
\ Create a thread with dictionary SPACE. Execute XT in thread.
: THREAD-COT ALLOT CTA CREATE RSP@ SWAP RSP! S0 @ R0 @
ROT RSP! 3 CELLS - , ,
DOES> $@ >R \ R@ is rsp of new task
@ R@ !
>DFA @ R@ CELL+ !
'EXIT-COT >DFA @ R@ CELL+ CELL+ !
R> TASK-TABLE BAG+! ;
\
-----------------------------------------
Example:
1000 THREAD COOS \ A small dict space to allow printing numbers
: jantje "we gaan naar Rome" TYPE CR ;
' jantje COOS
Now the text is printed and the task stops. Very exciting, but only
if you know what is going on.
Groetjes Albert
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why does the location of PAD move around? Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2017-04-01 21:07 -0400
Re: Why does the location of PAD move around? hughaguilar96@gmail.com - 2017-04-01 19:32 -0700
Re: Why does the location of PAD move around? Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2017-04-02 02:00 -0400
Re: Why does the location of PAD move around? Julian Fondren <julian.fondren@gmail.com> - 2017-04-01 23:51 -0700
Re: Why does the location of PAD move around? "Elizabeth D. Rather" <erather@forth.com> - 2017-04-01 21:59 -1000
Re: Why does the location of PAD move around? krishna.myneni@ccreweb.org - 2017-04-09 09:54 -0700
Re: Why does the location of PAD move around? Julian Fondren <julian.fondren@gmail.com> - 2017-04-01 20:10 -0700
Re: Why does the location of PAD move around? "Elizabeth D. Rather" <erather@forth.com> - 2017-04-01 18:39 -1000
Re: Why does the location of PAD move around? Mark Wills <markwills1970@gmail.com> - 2017-04-02 08:29 -0700
Re: Why does the location of PAD move around? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-04-02 04:13 -0500
Re: Why does the location of PAD move around? Paul Rubin <no.email@nospam.invalid> - 2017-04-02 18:08 -0700
Re: Why does the location of PAD move around? Julian Fondren <julian.fondren@gmail.com> - 2017-04-02 18:13 -0700
Re: Why does the location of PAD move around? Paul Rubin <no.email@nospam.invalid> - 2017-04-02 18:22 -0700
Re: Why does the location of PAD move around? Julian Fondren <julian.fondren@gmail.com> - 2017-04-02 18:31 -0700
Re: Why does the location of PAD move around? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-03 04:37 +0200
Re: Why does the location of PAD move around? Paul Rubin <no.email@nospam.invalid> - 2017-04-02 22:04 -0700
Re: Why does the location of PAD move around? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-04 13:47 +0200
Re: Why does the location of PAD move around? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-04-04 10:53 -0500
Re: Why does the location of PAD move around? Alex <alex@rivadpm.com> - 2017-04-04 17:04 +0100
Re: Why does the location of PAD move around? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-04 19:00 +0200
Re: Why does the location of PAD move around? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-04-05 03:39 -0500
Re: Why does the location of PAD move around? Alex <alex@rivadpm.com> - 2017-04-05 19:17 +0100
Re: Why does the location of PAD move around? "Elizabeth D. Rather" <erather@forth.com> - 2017-04-02 21:44 -1000
Re: Why does the location of PAD move around? "Elizabeth D. Rather" <erather@forth.com> - 2017-04-02 21:35 -1000
Re: Why does the location of PAD move around? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-04-03 03:38 -0500
Re: Why does the location of PAD move around? "HAA" <someone@microsoft.com> - 2017-04-05 11:25 +1000
Re: Why does the location of PAD move around? Paul Rubin <no.email@nospam.invalid> - 2017-04-05 18:23 -0700
Re: Why does the location of PAD move around? "HAA" <someone@microsoft.com> - 2017-04-07 14:26 +1000
Re: Why does the location of PAD move around? Alex <alex@rivadpm.com> - 2017-04-07 08:47 +0100
Re: Why does the location of PAD move around? "HAA" <someone@microsoft.com> - 2017-04-08 10:25 +1000
Re: Why does the location of PAD move around? Paul Rubin <no.email@nospam.invalid> - 2017-04-07 20:37 -0700
Re: Why does the location of PAD move around? Alex <alex@rivadpm.com> - 2017-04-08 12:42 +0100
Re: Why does the location of PAD move around? jason.songhurst@gmail.com - 2017-04-08 20:28 -0700
Re: Why does the location of PAD move around? Coos Haak <htrofhc@gmail.com> - 2017-04-09 13:47 +0200
Re: Why does the location of PAD move around? "Elizabeth D. Rather" <erather@forth.com> - 2017-04-09 08:36 -1000
Re: Why does the location of PAD move around? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-09 14:48 +0200
Re: Why does the location of PAD move around? "HAA" <someone@microsoft.com> - 2017-04-10 10:31 +1000
Re: Why does the location of PAD move around? Alex <alex@rivadpm.com> - 2017-04-10 09:29 +0100
Re: Why does the location of PAD move around? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-10 11:57 +0200
Re: Why does the location of PAD move around? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-03 03:43 +0200
Re: Why does the location of PAD move around? "Elizabeth D. Rather" <erather@forth.com> - 2017-04-02 21:53 -1000
Re: Why does the location of PAD move around? "HAA" <someone@microsoft.com> - 2017-04-02 21:31 +1000
Re: Why does the location of PAD move around? Coos Haak <htrofhc@gmail.com> - 2017-04-02 15:12 +0200
Re: Why does the location of PAD move around? "HAA" <someone@microsoft.com> - 2017-04-03 10:46 +1000
Re: Why does the location of PAD move around? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-03 03:31 +0200
Re: Why does the location of PAD move around? hughaguilar96@gmail.com - 2017-04-02 19:14 -0700
Re: Why does the location of PAD move around? "Elizabeth D. Rather" <erather@forth.com> - 2017-04-02 21:55 -1000
Re: Why does the location of PAD move around? "HAA" <someone@microsoft.com> - 2017-04-04 11:06 +1000
Re: Why does the location of PAD move around? Alex <alex@rivadpm.com> - 2017-04-04 12:54 +0100
Re: Why does the location of PAD move around? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-04 16:27 +0000
Re: Why does the location of PAD move around? Alex <alex@rivadpm.com> - 2017-04-04 19:23 +0100
Re: Why does the location of PAD move around? hughaguilar96@gmail.com - 2017-04-07 22:04 -0700
Re: Why does the location of PAD move around? hughaguilar96@gmail.com - 2017-04-02 14:21 -0700
Why does the location of PAD move around? Mark Wills <markwills1970@gmail.com> - 2017-04-02 08:28 -0700
Re: Why does the location of PAD move around? hughaguilar96@gmail.com - 2017-04-02 13:47 -0700
Re: Why does the location of PAD move around? hughaguilar96@gmail.com - 2017-04-02 15:13 -0700
Re: Why does the location of PAD move around? hughaguilar96@gmail.com - 2017-04-02 18:55 -0700
csiph-web