1 \section{\class{wxCondition
}}\label{wxcondition
}
3 wxCondition variables correspond to pthread conditions or to Win32 event
4 objects. They may be used in a multithreaded application to wait until the
5 given condition becomes true which happens when the condition becomes signaled.
7 For example, if a worker thread is doing some long task and another thread has
8 to wait until it is finished, the latter thread will wait on the condition
9 object and the worker thread will signal it on exit (this example is not
10 perfect because in this particular case it would be much better to just
11 \helpref{Wait()
}{wxthreadwait
} for the worker thread, but if there are several
12 worker threads it already makes much more sense).
14 Note that a call to
\helpref{Signal()
}{wxconditionsignal
} may happen before the
15 other thread calls
\helpref{Wait()
}{wxconditionwait
} but, in marked contrast
16 with the pthread conditions, this will still work as the missed signals are
17 queued and
\helpref{Wait()
}{wxconditionwait
} simply returns immediately if
18 there are ny pending signals.
20 However, the calls to
\helpref{Broadcast()
}{wxconditionbroadcast
} are
{\bf not
}
21 queued and so it will only wake up the threads already waiting on the
22 condition. Accordingly, you will probably want to use a mutex to ensure that
23 the thread(s) you want to be waken up have indeed started to wait before
24 calling
\helpref{Broadcast()
}{wxconditionbroadcast
}.
28 This example shows how a main thread may launch a worker thread and wait until
32 class MyWaitingThread : public wxThread
35 MyWaitingThread(wxCondition *condition)
37 m_condition = condition;
42 virtual ExitCode Entry()
44 // let the main thread know that we started running
45 m_condition->Signal();
53 wxCondition *m_condition;
58 wxCondition condition;
59 MyWaitingThread *thread - new MyWaitingThread(&condition);
63 // wait until the thread really starts running
72 \wxheading{Derived from
}
76 \wxheading{Include files
}
82 \helpref{wxThread
}{wxthread
},
\helpref{wxMutex
}{wxmutex
}
84 \latexignore{\rtfignore{\wxheading{Members
}}}
86 \membersection{wxCondition::wxCondition
}\label{wxconditionconstr
}
88 \func{}{wxCondition
}{\void}
92 \membersection{wxCondition::
\destruct{wxCondition
}}
94 \func{}{\destruct{wxCondition
}}{\void}
96 Destroys the wxCondition object.
98 \membersection{wxCondition::Broadcast
}\label{wxconditionbroadcast
}
100 \func{void
}{Broadcast
}{\void}
102 Broadcasts to all waiting objects.
104 \membersection{wxCondition::Signal
}\label{wxconditionsignal
}
106 \func{void
}{Signal
}{\void}
110 \membersection{wxCondition::Wait
}\label{wxconditionwait
}
112 \func{void
}{Wait
}{\void}
116 \func{bool
}{Wait
}{\param{unsigned long
}{ sec
},
\param{unsigned long
}{ nsec
}}
118 Waits until a signal is raised or the timeout has elapsed.
120 \wxheading{Parameters
}
122 \docparam{sec
}{Timeout in seconds
}
124 \docparam{nsec
}{Timeout nanoseconds component (added to
{\it sec
}).
}
126 \wxheading{Return value
}
128 The second form returns if the signal was raised, or FALSE if there was a timeout.