问题
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