Posted: Mon Nov 05, 2007 6:15 am
That seems like the best solution. The framework will start it's own thread in the background, that'll handle all kernel events.Candy wrote:Double threaded application, one thread managed by the framework that handles the messages, the other can only read/write to/from predefined streams that block sending a message to the other thread waiting for a reply. The framework thread is asynchronous, the other is synchronous, without problems and without a dozen message loops.
This is an example of how a getchar() implementation would work:
(Program Thread = The program's primary thread.
Framework Thread = The background thread created by the framework for handling events.)
- Program Thread: getchar() is called
Program Thread: set some variable somewhere to say we're waiting for a key input
Program Thread: place self in an idle state
System: Key is pressed
Kernel: Send "Key down" message to Framework Thread. (Which wakes up the framework thread.)
Framework Thread: Receives the key down message from the kernel.
Framework Thread: Translate the key message into an ASCII character.
Framework Thread: Realise getchar() is waiting for a variable and wake Program Thread.
Program Thread: getchar() returned the key pressed
Program Thread: thread continues executing more code as before
In the near future I'm hoping to have the framework dynamically linked, another advantage of having as much as possible in the framework rather than in the kernel, since the steps involved in a major system update to the input/GUI/etc may be as simple as:
- Tell all programs to save and exit.
- Install the new framework library.
- Restart all programs and reload work.
Instead of requiring a reboot to reload the kernel.