请教几种创建线程函数的区别

标  题: [合集] 请教几种创建线程函数的区别。

发信站: 水木社区 (Wed Oct 11 16:43:15 2006), 站内

☆─────────────────────────────────────☆ 

  zealotkuihua (葵花) 于  (Tue Oct  3 13:28:38 2006)  提到:

接触多线程编程有一段时间了。发现有多种创建线程的函数

1。 HANDLE WINAPI CreateThread(

  LPSECURITY_ATTRIBUTES lpThreadAttributes,

  SIZE_T dwStackSize,

  LPTHREAD_START_ROUTINE lpStartAddress,

  LPVOID lpParameter,

  DWORD dwCreationFlags,

  LPDWORD lpThreadId

);

2。uintptr_t _beginthread(

  void( __cdecl *start_address )( void * ),

  unsigned stack_size,

  void *arglist

);

uintptr_t _beginthreadex(

  void *security,

  unsigned stack_size,

  unsigned ( __stdcall *start_address )( void * ),

  void *arglist,

  unsigned initflag,

  unsigned *thrdaddr

);

3。CWinThread* AfxBeginThread(

  AFX_THREADPROC pfnThreadProc,

  LPVOID pParam,

  int nPriority = THREAD_PRIORITY_NORMAL,

  UINT nStackSize = 0,

  DWORD dwCreateFlags = 0,

  LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL

);

CWinThread* AfxBeginThread(

  CRuntimeClass* pThreadClass,

  int nPriority = THREAD_PRIORITY_NORMAL,

  UINT nStackSize = 0,

  DWORD dwCreateFlags = 0,

  LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL

);

这3种创建线程函数创建的线程有什么区别吗?

哪位大虾指点一下。

☆─────────────────────────────────────☆ 

  zealotkuihua (葵花) 于  (Wed Oct  4 13:51:22 2006)  提到:

难道我问错了版块?

【 在 zealotkuihua (葵花) 的大作中提到: 】                                     

: 接触多线程编程有一段时间了。发现有多种创建线程的函数                         

: 1。 HANDLE WINAPI CreateThread(                                             

:  LPSECURITY_ATTRIBUTES lpThreadAttributes,

: ...................                                                         

                                                                               

                                                                               

☆─────────────────────────────────────☆ 

  icubaby (不吃草的羊) 于  (Wed Oct  4 14:13:19 2006)  提到:

_beginthread and _beginthreadex are functions in std C library. _beginthreadex

is an extended version of _beginthread. CreateThread is a WINDOWS API, which

invoke _beginthreadex internally. AfxBeginThread is a global function in MFC,

which invokes CreateThread internally.

【 在 zealotkuihua (葵花) 的大作中提到: 】                                     

: 接触多线程编程有一段时间了。发现有多种创建线程的函数                         

: 1。 HANDLE WINAPI CreateThread(                                             

:  LPSECURITY_ATTRIBUTES lpThreadAttributes,                                 

: ...................

                                                                               

                                                                               

                                                                               

☆─────────────────────────────────────☆ 

  ftofficer (USTC::聪) 于  (Thu Oct  5 23:24:14 2006)  提到:

                                                                               

【 在 icubaby (不吃草的羊) 的大作中提到: 】                                   

: _beginthread is in std C library. _beginthreadex is an extended version of   

_beginthread.                                                                 

两者不是std C library的函数。

而是MS C Runtime扩展函数。

: CreateThread is a WINDOWS API, which invoke _beginthreadex internally.       

不是CreateThread调用_beginthreadex,而是_beginthreadex调用CreateThread.

: AfxBeginThread is a global function in MFC, which invokes Cr                 

: ...                                                                         

总体来说,CreateThread是Windows的API函数,提供操作系统级别的创建线程的操作。没有

太多额外的操作,直接调用到你的回调函数。_beginthreadex和_beginthread在回调入口函

数之前进行一些线程相关的CRT的初始化操作。AfxBeginThread内部调用了_beginthreadex

,并在此之前进行一些MFC相关的初始化工作。

                                                                               

                                                                               

                                                                               

☆─────────────────────────────────────☆ 

  bore (总有一些时候情绪比较低落|a za a za) 于  (Fri Oct  6 00:28:44 2006)  提?

                                                                               

错了吧.

_beginthread,_beginthreadex调CreateThread吧.

CreateThread某些时候有副作用而_beginthreadex没有,说明是_beginthreadex 调了

CreateThread

【 在 icubaby (不吃草的羊) 的大作中提到: 】                                   

: _beginthread and _beginthreadex are functions in std C library.             

_beginthreadex is an extended version of _beginthread. CreateThread is a       

WINDOWS API, which invoke _beginthreadex internally. AfxBeginThread is a global

function in MFC, which invokes CreateThread internally.                       

                                                                               

                                                                               

                                                                               

                                                                               

☆─────────────────────────────────────☆ 

  yennar (原云) 于  (Fri Oct  6 08:02:15 2006)  提到:

                                                                               

总之不管谁都回最终回到CreateThread

【 在 bore (总有一些时候情绪比较低落|a za a za) 的大作中提到: 】               

: 错了吧.                                                                     

: _beginthread,_beginthreadex调CreateThread吧.                                 

: CreateThread某些时候有副作用而_beginthreadex没有,说明是_beginthreadex 调了   

CreateThread                                                                   

                                                                               

                                                                               

                                                                               

                                                                               

                                                                               

☆─────────────────────────────────────☆ 

  wjie (faint) 于  (Fri Oct  6 11:22:34 2006)  提到:

如果一个线程自己卡死了,有办法在主线程里把它强行结束吗?how

                                                                               

【 在 yennar (原云) 的大作中提到: 】                                           

: 总之不管谁都回最终回到CreateThread                                           

                                                                               

                                                                               

                                                                               

                                                                               

☆─────────────────────────────────────☆ 

  yennar (原云) 于  (Fri Oct  6 18:45:39 2006)  提到:

TerminateThread

可以考虑“看门狗”的设计思路

                                                                               

【 在 wjie (faint) 的大作中提到: 】                                           

: 如果一个线程自己卡死了,有办法在主线程里把它强行结束吗?how 

 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值