D
D
Door2013-07-17 23:14:22
C++ / C#
Door, 2013-07-17 23:14:22

Wait for an event from another thread without interrupting message processing?

Multithreading is an unknown topic for me, tell me how to do it right.
Actually, there is a non-main thread that performs some useful work and can notify (how?) The main thread about some event.
How can I make sure that window procedure message processing does not stop while waiting for this event? (That is, the goal is to keep the main window from "hanging" without responding to user requests).
Need to use PostMessage? Is there a possibility not to affect the window procedure (that is, not to send messages), something like WaitForSingleObject?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vScherba, 2013-07-17
@vScherba

MsgWaitForMultipleObjects[Ex]
If you use ATL in your project, you can use AtlWaitWithMessageLoop. And if you do not use it, then look at its source as an example of using MsgWaitForMultipleObjects.

A
Akson87, 2013-07-18
@Akson87

It is possible to check still in the main flow on the timer as there the additional flow lives. Although Post / SendMessage is more correct.

A
AxisPod, 2013-07-18
@AxisPod

You can generally just do it if there are guarantees that only 1 thread writes. Declare a volatile variable, put false there, for example, and start the thread, then write true at the end, and check its change in the main worker thread. If there is no guarantee that 1 thread will write, you can take std::atomic for example, if the compiler is old, then steal the implementation thread somewhere. Again, you can just use InterlockedIncrement and a family of functions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question