Is there was a mechanism in Windows works like message queue in Linux?

雨燕双飞 提交于 2019-12-18 07:00:03

问题


Recently, I got a job(C/C++) to use message communication between different threads in Windows. I Googled and find that the Windows also got a message queue too, but it is more related to a window, actually, I do not need any window in my application.

Like the message queue in Linux, each thread create a message queue and got a message queue ID, sending message to that ID, receive from that ID and so on, that is the message queue I need.

Is there any similar mechanism(s) in Windows works like that?


回答1:


You don't need a window to use messages on Windows, any thread that calls PeekMessage or GetMessage gets a message queue and you can post messages to it with PostThreadMessage.

Messages should work fine in the same process but if this is cross-process and you need to send more than size_t*2 you should look at other IPC mechanisms or build your own with shared memory and some type of locking. Windows also has MSMQ.

You did not specify if you need the exact POSIX interface or not, either way, Wikipedia has a list of open source alternatives...



来源:https://stackoverflow.com/questions/10989702/is-there-was-a-mechanism-in-windows-works-like-message-queue-in-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!