應用場景:
做了一個client,去和Message Middleware通信,實時獲取消息中間件以topic方式(不是Queue,對Message Middleware來說,Queue是發送一個destination,topic可以發多個)。
從實時獲取的角度來說,需要啟一個線程,接收Message Middleware消息,然后做場景需要的處理。創建線程的函數如下所示:
// for compilers which have it, we should use C RTL function for thread
// creation instead of Win32 API one because otherwise we will have memory
// leaks if the thread uses C RTL (and most threads do)
#if defined(__VISUALC__) || \
(defined(__BORLANDC__) && (__BORLANDC__ >= 0x500)) || \
(defined(__GNUG__) && defined(__MSVCRT__))
typedef unsigned (__stdcall *RtlThreadStart)(void *);
m_hThread = (HANDLE)_beginthreadex(NULL, 0,
(RtlThreadStart)
wxThreadInternal::WinThreadStart,
thread, CREATE_SUSPENDED,
(unsigned int *)&m_tid);
#else // compiler doesn't have _beginthreadex
m_hThread = ::CreateThread
(
NULL, // default security
0, // default stack size
(LPTHREAD_START_ROUTINE) // thread entry point
wxThreadInternal::WinThreadStart, // the function that runs under thread
(LPVOID)thread, // parameter
CREATE_SUSPENDED, // flags
&m_tid // [out] thread id
);
#endif // _beginthreadex/CreateThread
note: there should be a function definition before these lines.eg:
DWORD wxThreadInternal::WinThreadStart(wxThread *thread)
posted on 2008-09-26 09:07
chatler 閱讀(507)
評論(0) 編輯 收藏 引用 所屬分類:
OS