let some time to the system.
Etienne SOBOLE (3572) 28 posts |
Hi. I’ve test this simple programme int main() { while (1) { ... // somme computation }; } This simple program will freeze the system because it take all the cpu time. What is the correct method to realise huge quantity of computation without taking 100% of speed. thank’s |
Chris Hall (132) 3554 posts |
You need a SYS “Wimp_Poll” loop to do cooperative multitasking. Wimp_Poll returns to your programme after polling others. |
John Sandgrounder (1650) 574 posts |
Alternatively, run the program in a Task Window. |
GavinWraith (26) 1563 posts |
Or you might like to download RiscLua, put the seven lines below into a textfile, give it filetype Lua and doubleclick on the file’s icon.
|
Rick Murray (539) 13840 posts |
I’m suffering from a rather nasty bunged up sinus with a headache only marginally less than that time I had my wisdom teeth out, so maybe I’m missing something obvious, but… …Lua’s syntax looks really weird… |
Tristan M. (2946) 1039 posts |
Odd little mini programs always look a little weird though. Programming in Lua
See? Not so bad. Something about that whole x.handler thing reminds me vaguely of Windows 3.1. I vaguely recall having to do some funny little thing in code to allow task switching. |
Etienne SOBOLE (3572) 28 posts |
Thank you everybody. while (!quit) { reason = wimp_poll(wimp_MASK_NULL | wimp_MASK_ENTERING | wimp_MASK_LEAVING | wimp_MASK_GAIN | wimp_MASK_LOSE | wimp_MASK_POLLWORD, &block, NULL); switch (reason) { case wimp_USER_MESSAGE: case wimp_USER_MESSAGE_RECORDED: if (block.message.action == message_QUIT) quit = TRUE; break; } } Where should I put parts of my calculations ? |
Colin (478) 2433 posts |
If you are running the program in a taskwindow it freezes because there are no swis or functions which call swis in the while loop. Taskwindows only multitask when swis are called. So
should work. You don’t need to call the swi every iteration of the loop. |
Colin (478) 2433 posts |
If you were using an application you’d multitask on a null event something like this
Note wimp_poll no longer masks the null event. The Steve Fryatt example is the normal way of using wimp_poll in an application but if you want to multitask some complex calculation the above should work. |
Rick Murray (539) 13840 posts |
Tristan: while your little example isn’t bad and resembles many other languages… an example from Gavin’s own pages is: curry = \ (f) => \ (x) => \ (y) => f (x, y) end end end I rest my case. ;) Etienne: ignore cert message, nous parlons de Lua |
GavinWraith (26) 1563 posts |
@Rick Sorry about the sinuses. I used to have hell with those.
Two reasons here: 1. Lua lets you modify the syntax quite a bit. 2. What you are seeing is not Lua but RiscLua. So for example the construction in the second line is not standard Lua. To express it in standard Lua you would have to extend it to
What is happening here is that require searches for the library named by its argument and, if successful, returns the library as a table. There are two items we want from the task library: the item called task (yes, I know, same name, but why not?) and the item called QUIT. The first is a function of a string ( s ) returning a wimp-task object (x ) and the second is a handler that causes wimp-tasks to close down. In the fourth line it is being made the null-event handler for our wimp-task. The task library defines what sort of objects wimp-tasks are. In particular they have methods init , alert and run , used in the last three lines. Their names are self-explanatory, I hope.
What I am trying to show with things like the task library is how RiscLua can conceal a great deal of messy detail, which is what libraries are for, and let the programmer get on with describing what the program really does. Yes, I know that in the end the programmer may in some circumstances have to grapple with the details, and the pain of those will be the same in any language. If you look at my notes you will see my arguments for why higher-order languages are better equipped for abstracting complicated things like wimp-tasks. |
Etienne SOBOLE (3572) 28 posts |
Thank’s colin. I prefer this code (but this is the same thing) int main() { ... while (!quit) { reason = wimp_poll(wimp_MASK_NULL | wimp_MASK_ENTERING | wimp_MASK_LEAVING | wimp_MASK_GAIN | wimp_MASK_LOSE | wimp_MASK_POLLWORD, &block, NULL); switch (reason) { case wimp_ENULL: compute_a_little_bit(); break; case wimp_USER_MESSAGE: case wimp_USER_MESSAGE_RECORDED: if (block.message.action == message_QUIT) quit = TRUE; break; } }; ... } I’ll try this evening… |
Colin (478) 2433 posts |
You need to remove the wimp_MASK_NULL from wimp_poll. |
Etienne SOBOLE (3572) 28 posts |
oups. |
Steve Drain (222) 1620 posts |
Time to join in the simplicity game. ;-) *BasaltInit REGW @Wimp_Null FNcalculate INITIALISE "Calculate" POLL END DEFFNcalculate ... ENDFN I am not sure where the output goes, though. |
Jeff Doggett (257) 234 posts |
The point is that Riscos is a cooperative multitasking system, not preemptive. The Task Window Application allows ordinary programs to run by preempting them as a single task in the window. |
GavinWraith (26) 1563 posts |
@Rick A propos curry google Haskell Brooks Curry. |
Etienne SOBOLE (3572) 28 posts |
colin case wimp_ENULL: doesn’t exists I used case wimp_NULL_REASON_CODE instead. It seem’s to work. The program works. I still not know how to stop it but, it let the desktop working. thx |
Colin (478) 2433 posts |
I don’t use the library you are using so I just guessed the name. You can quit the program from the task manager. 1) click on task manager icon – bottom right of screen. The task manager sends the message_QUIT message which you have set to quit the program. |