我想用 mfc 编写多线程就是没有成功.请求大家给点示例,最好有注释.
线程之间如何通信.

解决方案 »

  1.   

    class CMyThread : public CWinThread
    {
    DECLARE_DYNCREATE(CMyThread)
    public:
    //初始化线程标号和对话框指针
    CMyThread(int m_ID);           // protected constructor used by dynamic creation// Attributes
    public:// Operations
    public:
    int ID; //线程标号
    bool IsWork; //线程工作标志
    CMySocket m_sAcceptSocket; //接受连接套接字// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMyThread)
    public:
    virtual BOOL InitInstance();
    virtual int ExitInstance();
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CMyThread(); // Generated message map functions
    //{{AFX_MSG(CMyThread)
    // NOTE - the ClassWizard will add and remove member functions here.
    //}}AFX_MSG DECLARE_MESSAGE_MAP()
    }; m_Thread[i] = new CMyThread(i);
    if (!m_Thread[i]->CreateThread(CREATE_SUSPENDED))
    {
    for(int j = 0; j < i; j++)
    if(m_Thread[j] != NULL)
    {
    m_Thread[i]->ExitInstance();
    m_Thread[j] = NULL;
    }
    delete m_Thread[j];
    m_Thread[i] = NULL;
    AfxMessageBox("线程建立错误!",MB_OK|MB_ICONSTOP);
    return;
    }
      

  2.   

    谢谢你!,我想让你给我完整例子,说明实现什么功能好吗?
      比如有一个全局变量 Busy =true,那么
      while(Busy)
      {
         MessageBee(0);
       }//如果假设是 Thread_2;
       进程3 Thread_3 把 Busy = false;并告知
          if(! Busy)
          {
             Busy =false;
             MessageBox(" 歇会再响吧 ");
           }