應(yīng)用場(chǎng)景:
做了一個(gè)client,去和Message Middleware通信,實(shí)時(shí)獲取消息中間件以topic方式(不是Queue,對(duì)Message Middleware來說,Queue是發(fā)送一個(gè)destination,topic可以發(fā)多個(gè))。
從實(shí)時(shí)獲取的角度來說,需要啟一個(gè)線程,接收Message Middleware消息,然后做場(chǎng)景需要的處理。創(chuàng)建線程的函數(shù)如下所示:
// 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)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
OS