I'm implementing a Win32 Console text editor that has an internal message queue for passing around information about which areas to redraw, messages to/from plugins, etc. I prefer it to be single-threaded by default (if there's nothing happening that requires additional threads). I'm considering 2 message queue implementation strategies:
- Use general-purpose queue and Win32 Event, so I can use
WaitForMultipleObjectsEx
to wait for internal messages and user input simultaneously, passing both console input handle and Event handle. In this case, text editor can live entirely within a single thread. - Use I/O Completion Port. In this case, text editor will need at least two threads, one of them calling
GetQueuedCompletionStatus
to get messages, and another reading user input and sending it to queue viaPostQueuedCompletionStatus
. The reason it that console input handle cannot be overlapped andWaitFor*
functions don't accept Completion Port as a waitable handle, so it's not possible to wait on them simultaneously. Just like in the first setup, both threads don't waste CPU time when there's no input or events, but each keypress has to be passed from one thread to another via IOCP.
Which design is overall better?
Is performance and latency drawback from passing each keypress via IOCP significant for a text editor?