CreateSemaphore信号灯怎么使用?哪位仁兄有实例? - C++ Builder / Windows SDK/API
我想实现多线程的同步
1.如何使用信号灯实现两个任务的同步?
2.以实例说明线程的应用及其效果?
其它方法也行
[解决办法]
实例1技术要点 互斥量同步的多线程示例程序:
unit1.h 和 unit1.cpp
- C/C++ code
#ifndef Unit1H#define Unit1H//---------------------------------------#include "Unit2.h"#include "Unit3.h"#include <Classes.hpp>#include <Controls.hpp>#include <StdCtrls.hpp>#include <Forms.hpp>//#include <Syncobjs.hpp>//---------------------------------------class TForm1 : public TForm{__published: // IDE-managed Components TMemo *Memo1; TButton *Button1; void __fastcall FormCreate(TObject *Sender); void __fastcall Button1Click(TObject *Sender);private: // User declarations TReverseThread *ReverseThread; TDisplayThread *DisplayThread;public: // User declarations char LetterTable[26]; HANDLE hMutex; __fastcall TForm1(TComponent* Owner);};//---------------------------------------extern PACKAGE TForm1 *Form1;//---------------------------------------#endif