开发者

Why use GetMessage/DispatchMessage when threads are doing all the work?

开发者 https://www.devze.com 2023-03-18 10:49 出处:网络
I have two versions of a minimal web server. Both execute an infinite loop that re开发者_C百科ceives incoming requests and creates a thread to service each request.

I have two versions of a minimal web server.

Both execute an infinite loop that re开发者_C百科ceives incoming requests and creates a thread to service each request.

One version simply starts executing that infinite loop.

The other version creates a special thread to execute the infinite loop, and the main program then drops into a standard Windows GetMessage/DispatchMessage loop.

Neither version has a GUI or a console window, they both simply run invisibly, and there's no mechanism coded to make the programs quit (ie, deliberately exit any of their loops).

Any guesses as to why one version uses the extra thread plus GetMessage/DispatchMessage?


It could be habit, based on the habits of the developers of the respective versions. Someone more accustomed to GUI coding might be more likely to add the GetMessage/DispatchMessage code. They may have started with a standard template and adjusted to create the specific project.

Or it could be deliberate -- maybe someone anticipated adding a GUI or some housekeeping tasks in the main thread. Or maybe a watchdog mechanism, where if the infinite loop were to crash (due to an uncaught exception, for instance) the main thread would automatically restart the loop.

I could be way off base, but the question does ask for guesses.

0

精彩评论

暂无评论...
验证码 换一张
取 消