TCountdownEvent (C++)
Description
The following example is a console application that illustrates the use of the TCountdownEvent class.
Code
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
#include <Classes.hpp>
#include <iostream.h>
using namespace std;
// ---------------------------------------------------------------------------
#pragma argsused
static TCountdownEvent *runwayFlag;
class TThreadIgnite : public TThread {
private:
void __fastcall Execute() {
runwayFlag->WaitFor();
// Next statements are executed only
// after runwayFlag->CurrentCount becomes 0
cout << runwayFlag->CurrentCount << " -> Ignited" << endl;
}
public:
TThreadIgnite(bool createSuspended) : TThread(createSuspended) {
}
};
int _tmain(int argc, _TCHAR* argv[]) {
runwayFlag = new TCountdownEvent(200);
runwayFlag->Reset();
TThread *thread = new TThreadIgnite(true);
thread->Start();
while (runwayFlag->IsSet == false) {
cout << runwayFlag->CurrentCount << endl;
runwayFlag->Signal();
}
Sleep(10); // Let the thread print the message "0 -> Ignited"
return 0; // Put breakpoint here to see the console output.
}
Uses
- System.SyncObjs.TCountdownEvent ( fr | de | ja )
- System.SyncObjs.TCountdownEvent.Signal ( fr | de | ja )
- System.SyncObjs.TCountdownEvent.WaitFor ( fr | de | ja )