1 / 24

More on threads

2. . MFC's thread implementation MFC Internals by G. Shepherd, S. WingoExecuting a class member in its own thread (C/C Users Journal, Vol.17, No. 12, p. 57)Singleton Creation the thread-safe way (C/C Users Journal, Vol.17, No. 10, p. 43)Improving performance with thread-private heaps (C/C U

shing
Download Presentation

More on threads

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. 1 More on threads Konstantin Bukin CSE791 – Advanced Windows Programming Summer 2001

    2. 2 MFC’s thread implementation MFC Internals by G. Shepherd, S. Wingo Executing a class member in its own thread (C/C++ Users Journal, Vol.17, No. 12, p. 57) Singleton Creation the thread-safe way (C/C++ Users Journal, Vol.17, No. 10, p. 43) Improving performance with thread-private heaps (C/C++ Users Journal, Vol.17, No. 9, p. 50)

    3. 3 Thread’s thread creation CWinThread* AFXAPI AfxBeginThread(AFX_THREADPROC pfnThreadProc, LPVOID pParam, int nPriority, UINT nStackSize, DWORD dwCreateFlags, LPSECURITY_ATTRIBUTES lpSecurityAttrs); CWinThread* AFXAPI AfxBeginThread(CRuntimeClass* pThreadClass, int nPriority, UINT nStackSize, DWORD dwCreateFlags, LPSECURITY_ATTRIBUTES lpSecurityAttrs);

    4. 4 AfxBeginThread() CWinThread* pThread = new CWinThread(pfnThreadProc, pParam); if (!pThread->CreateThread( dwCreateFlags | CREATE_SUSPENDED, nStackSize, lpSecurityAttrs)) { pThread->Delete(); return NULL; } VERIFY(pThread->SetThreadPriority(nPriority)); if (!(dwCreateFlags & CREATE_SUSPENDED)) VERIFY(pThread->ResumeThread() != (DWORD)-1); return pThread; It’s all about CWinThread and it’s CreateThread()

    5. 5 CWinThread class CWinThread : public CCmdTarget { public: CWinThread(); CWinThread(AFX_THREADPROC pfnThreadProc, LPVOID pParam); BOOL CreateThread(DWORD dwCreateFlags = 0, UINT nStackSize = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL); virtual BOOL InitInstance(); virtual int Run(); virtual BOOL PreTranslateMessage(MSG* pMsg); virtual BOOL PumpMessage(); // low level message pump virtual BOOL OnIdle(LONG lCount); //return TRUE if more idle processing virtual BOOL IsIdleMessage(MSG* pMsg); //checks for special messages private: LPVOID m_pThreadParams; //generic parameters passed to starting function AFX_THREADPROC m_pfnThreadProc; HANDLE m_hThread; // this thread's HANDLE } Back to AfxBeginThread()

    6. 6 CWinThread::CreateThread()

More Related