Author |
Topic: Pausing and restarting multiple PROCs ? (Read 569 times) |
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Pausing and restarting multiple PROCs ?
« Thread started on: Jun 15th, 2012, 10:01pm » |
|
This thread has been moved across from the Yahoo! group.
Quote:Can you perhaps briefly clarify for me what it is about "saving and restoring the stack" which needs to be done? |
|
The stack contains vital information related to FOR...NEXT, REPEAT...UNTIL and WHILE...ENDWHILE loops. So if the stack isn't saved as part of a task's context such features won't work correctly, which would be a pretty serious limitation! The stack also contains saved LOCAL and PRIVATE variables, and the contents of LOCAL arrays and structures, so again those features won't work in a multi-tasking environment unless the stack is saved as part of the context.
Quote:My programme does seem to work (Yes?) |
|
I haven't been able to try it, since you haven't said where it is or what it's called! If it appears to work (without the stack being saved) I would assume it does not use any of the above features.
Richard.
|
|
Logged
|
|
|
|
19Grumpah42
Junior Member
member is offline


Gender: 
Posts: 57
|
 |
Re: Pausing and restarting multiple PROCs ?
« Reply #1 on: Jun 16th, 2012, 05:54am » |
|
Thanks for moving the thread across to where you wanted it, I appreciate that.
I take the point about code "wrapping" on the Group site's e-mail, it is an inconvenience. I had already posted the .BBC prog before I opened this message, so it's in the "Miscellaneous" folder, called RTE_Simple.bbc
I look forward to receiving your comments. I do confess that I have no clear idea about what you perceive as "stack necessities", I just wrote this with simple BASIC, I like to keep things as simple as possible. This demo just toggles between two PROCs on a fixed cycle, because both of these "run forever". but I have others which schedule both very quick and long-running PROCs so the 'executive' just places a maximum amount of time available to each PROC each time slice.
--Grahame
|
|
Logged
|
C-2-Q 3GB, C-2-Duo 2GB, both GeForce 9500 GT, WinXP sp3. Two Linux Ubuntu boxes (rock solid, lean and mean, but they won't run BB4W!).
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Pausing and restarting multiple PROCs ?
« Reply #2 on: Jun 16th, 2012, 09:51am » |
|
on Jun 16th, 2012, 05:54am, 19Grumpah42 wrote:This demo just toggles between two PROCs on a fixed cycle |
|
I'm not sure whether I'm not understanding what you are trying to achieve, or whether you're not understanding what 'multi-tasking' entails, but your program appears to be carrying out no task switching at all!
As far as I can see you simply have a pair of PROCs which are called alternately, and which are both arranged to return when a particular time period has elapsed:
Code: REPEAT
PROC`subord`text
PROC`subord`graphics
UNTIL INKEY(0)=&1B
It works, as far as it goes, but each 'task' has to explicitly preserve its own 'context' using PRIVATE variables, automatically restarting loops in the correct place and so on, and whilst this is practical for the trivial tasks you have used it wouldn't be for anything more complicated.
So this isn't 'task switching' by any definition I would use, and isn't anything like what I was attempting (genuine multi-tasking in BBC BASIC).
Richard.
|
« Last Edit: Jun 16th, 2012, 4:58pm by admin » |
Logged
|
|
|
|
19Grumpah42
Junior Member
member is offline


Gender: 
Posts: 57
|
 |
Re: Pausing and restarting multiple PROCs ?
« Reply #3 on: Jun 19th, 2012, 01:43am » |
|
Thanks for providing a reply, always good for someone to show interest.
Quote:I'm not sure whether I'm not understanding what you are trying to achieve, or whether you're not understanding what 'multi-tasking' entails, but your program appears to be carrying out no task switching at all! |
|
Hm, I think that "multi-tasking" was your term not mine. There is nothing obscure about the little demo, it is decidedly pedestrian really, is just does what it shows: switches between the two PROCs on a time clock.
Quote:each 'task' has to explicitly preserve its own 'context' using PRIVATE variables, automatically restarting loops in the correct place and so on, |
|
Yes, of course you figured that one out!
Quote:whilst this is practical for the trivial tasks you have used it wouldn't be for anything more complicated. |
|
I am not aiming to create a multi-user multi-tasking sub-operating system. I am just doing things which are useful to me when I want a programme to juggle several balls at once. If by "more complicated" you mean something which exceeds our imagination to solve it with these simple BASIC commands (thank you BB4W) then your proposition is arguably self-fulfilling. You say you have failed to create the system you wanted, so unfortunately you cannot share it with us. I just aim to do what can be done.
My original question still remains: Does the demo contain anything which - due to my ignorance of more sophisticated tenchnical matters - could be considered "dangerous" or "nasty". Hopefully not, otherwise I must change my strategy before I have gone too far!
Thanks again, best of luck! --Grahame
|
|
Logged
|
C-2-Q 3GB, C-2-Duo 2GB, both GeForce 9500 GT, WinXP sp3. Two Linux Ubuntu boxes (rock solid, lean and mean, but they won't run BB4W!).
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Pausing and restarting multiple PROCs ?
« Reply #4 on: Jun 19th, 2012, 05:37am » |
|
on Jun 19th, 2012, 01:43am, 19Grumpah42 wrote:Hm, I think that "multi-tasking" was your term not mine. |
|
You described it as a "time-sharing run-time executive (an RTE)" which, to me, implies task-switching.
Quote:I am just doing things which are useful to me when I want a programme to juggle several balls at once. |
|
The technique you have adopted cannot practically be extended to a situation in which the tasks do something more complicated than a simple loop. Suppose a task uses nested loops, or performs two or more operations in sequence. In those cases - which are still untypically simple - the saving-and-restoring of context (which is already quite messy in your trivial example) will rapidly become unmanageable.
Personally I don't think the term RTE can reasonably be applied to what you are doing. There is some time-sharing, but where is the "executive" if each task has responsibility for testing that its time-slice has elapsed and for saving/restoring its context?
Quote:My original question still remains: Does the demo contain anything which - due to my ignorance of more sophisticated technical matters - could be considered "dangerous" or "nasty" |
|
It's "dangerous" because it involves messy code, which cannot be understood 'at a glance' and which will be very difficult to test and debug.
You can write a program which appears to be doing 'several things at once' without introducing anything as complicated, and risky, as the code you have listed. Typically there is no need to divide the tasks into 'time slices', which is the key complicating feature of your code. Instead simply get each procedure to perform a processing 'chunk' which is a natural unit, such as one iteration of a loop. It probably doesn't matter if it takes a microsecond or a millisecond, so long as it takes only a short time.
That way there's no need for a timer interrupt, no need for tasks to monitor how long they have been running, and the saving and restoring of context is hugely simplified. By stripping the program of all the overheads associated with your 'RTE' it will be shorter, faster, easier to understand and more reliable.
Richard.
|
« Last Edit: Jun 19th, 2012, 05:42am by admin » |
Logged
|
|
|
|
19Grumpah42
Junior Member
member is offline


Gender: 
Posts: 57
|
 |
Re: Pausing and restarting multiple PROCs ?
« Reply #5 on: Jun 20th, 2012, 07:23am » |
|
Thanks for the detailed reply, I'm definitely relieved to hear that there is nothing fundamental wrong with my little example. I was surprised that you consider PRIVATE variables to be "messy", but never mind.
Quote:It's "dangerous" because it involves messy code, which cannot be understood 'at a glance' and which will be very difficult to test and debug. |
|
Well, no need for you to fret! If you have difficulty understanding my "trivial" example, just leave it for others to get on with. I am now implementing a controlled and extended version of the structured and cascaded error trapping methods, as you strongly recommended, so debugging is very straightforward, and this little programme is - of course - a test in its own right, so I guess it was easy to test. Don't worry, I'm quite happy now.
--Grahame
|
|
Logged
|
C-2-Q 3GB, C-2-Duo 2GB, both GeForce 9500 GT, WinXP sp3. Two Linux Ubuntu boxes (rock solid, lean and mean, but they won't run BB4W!).
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Pausing and restarting multiple PROCs ?
« Reply #6 on: Jun 20th, 2012, 08:23am » |
|
on Jun 20th, 2012, 07:23am, 19Grumpah42 wrote:If you have difficulty understanding my "trivial" example, just leave it for others to get on with. |
|
Very droll. 
Richard.
|
|
Logged
|
|
|
|
|