Hi,
I’m used to C/C++, learning Ada, I’m trying to implement a tetris clone.
I didn’t want to bother with a GUI framework initially, so I started with basic CLI primitives:
- Each “frame” I just
Ada.Text_IO.Put_Line
to blast out the “playing field” - Using
Ada.Text_IO.Get_Immediate
to get input from the user. (Later using ada-evdev Read to get keypress events)
In order to receive the inputs from the user asynchronously, I created a separate task, which worked ok but I ran into the interesting
difference between C++ and ada: An unhandled exception doesn’t automatically terminate the program. Ok, I think its good to clean everything up anyways.
So now I end up with the following statements:
- I would prefer to use a blocking function for getting inputs, rather than one that does a nonblocking operation in a loop with a very short delay.
(That would probably lead to many unnecessary context switches/syscalls? Lot of unnecessary CPU time spent spinning waiting for input?) - I would like to be able to signal my thread to do any cleanup and then exit
(maybe read any pending stdin characters and termios re-enable echo so the terminal isn’t weird when the program exits)
What is a reasonable way of doing this?
This issue probably also applies to things like network IO from sockets, but I haven’t done any socket programming in Ada yet… but I guess the story would be:
- I have a dedicated task for handling incoming connections and traffic.
- It’s blocked waiting for some client input (or some timeout?).
- I get an exception in some other thread and want to exit immediately.
Is throwing an abort
at the blocked task the best option?
e.g.
- Add a handler for task termination
- make the non-blocking part of the task subprogram some abort-deferred block? (protected something?)
so I know that if I throw an abort
at it, if it was already doing something, it will finish that thing before being kicked to the termination handler?