beginthreadex例子 beginthreadex用法

基础知识:

uintptr_t _beginthread(    void( *start_address )( void * ),   unsigned stack_size,   void *arglist );uintptr_t _beginthreadex(    void *security,   unsigned stack_size,   unsigned ( *start_address )( void * ),   void *arglist,   unsigned initflag,   unsigned *thrdaddr );
start_address

Start address of a routine that beginsexecution of a new thread. For _beginthread, the calling

convention is either __cdecl or __clrcall; for _beginthreadex, it iseither __stdcall or __clrcall.

stack_size

Stack size for a new thread or0.

arglist

Argument list to be passed to a newthread or NULL.

security

Pointer to a SECURITY_ATTRIBUTESstructure that determines whether the returned handle can be

inherited by child processes. IfNULL, the handle cannot be inherited.Must be NULL for Windows

95 applications.

initflag

Initial state of a new thread(0 for running or CREATE_SUSPENDED forsuspended); use ResumeThread

to execute the thread.

thrdaddr

Points to a 32-bit variable thatreceives the thread identifier. Might be NULL, in which case it is

not used.

在msdn中这样的例子:
是关于_beginthreadex的
// crt_begthrdex.cpp
// compile with: /MT
#include <windows.h>
#include <stdio.h>
#include <process.h>

unsigned Counter;
unsigned __stdcall SecondThreadFunc( void* pArguments )
{
printf( "In second thread...n" );

while ( Counter < 1000000 )
Counter++;

_endthreadex( 0 );
return 0;
}

int main()
{
HANDLE hThread;
unsigned threadID;

printf( "Creating second thread...n" );

// Create the second thread.
hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0, &threadID ); //NULL表示无传递参数

// Wait until second thread terminates. If you comment out the line
// below, Counter will not be correct because the thread has not
// terminated, and Counter most likely has not been incremented to
// 1000000 yet.
WaitForSingleObject( hThread, INFINITE );
printf( "Counter should be 1000000; it is-> %dn", Counter );
// Destroy the thread object.
CloseHandle( hThread );
}

=======================

有传递参数:

#include <windows.h>
#include <stdio.h>
#include <process.h>

typedef struct play_s
{
intsliderRange;

} Play_Param;

unsigned Counter;
unsigned __stdcall SecondThreadFunc( void* pArguments )
{
Play_Param*pp = (Play_Param *) pArguments;

int aa = pp->sliderRange;


while ( Counter < 1000000 )
Counter++;

beginthreadex例子 beginthreadex用法
_endthreadex( 0 );
return 0;
}

int main()
{
HANDLE hThread;
Play_Paramparam;

param.sliderRange =1000;
hThread = (HANDLE)_beginthreadex( NULL, 0,&SecondThreadFunc, &param,0,NULL);

//&param表示传递参数
WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );
}

---------------------

void Start(Play_Param *param)
{
setState(RUN);//设置运行标示

if( hThread == 0 &&::WaitForSingleObject(hThread ,1) == WAIT_TIMEOUT)

//判断是否在运行
hThread = (HANDLE)_beginthreadex( NULL, 0,&SecondThreadFunc, param, 0,NULL);

}

  

爱华网本文地址 » http://www.aihuau.com/a/25101017/365220.html

更多阅读

的地得的用法 的和地的区别及用法

的地得的用法——简介日常工作中,常会有人提到“的”“地”“得”用法的问题,不少学生对“的、地、得”用法也是含糊不清,乱用一气,作业自然会在“的”“地”“得”用法上出错,并且屡改屡犯。大家都知道,“的”、“地”、“得”这三个字的

眼线膏的用法画出迷人眼线 美宝莲眼线膏

眼线膏的用法画出迷人眼线——简介美眉们一般都习惯用眼线笔来画眼线,今天小编要在这里教大家如何用眼线膏来描画眼线,步骤很简单,想要画好眼妆的美眉们,赶紧准备好工具,跟小编一起来学习吧!眼线膏的用法画出迷人眼线——工具/原料

睫毛膏的正确用法 睫毛膏如何使用

  睫毛膏对于很多女孩子来说其实并不陌生,但是大家真的知道睫毛膏的正确用法吗,如何使用睫毛膏才能让自己的睫毛更翘、更卷,而且看起来不会显得很僵硬呢,如果你还不懂那就来一起学习一下睫毛膏的正确用法吧。睫毛膏的正确用法——工

财务凭证装订机用法 财务凭证装订机维修

财务凭证装订机用法——简介热熔管财务装订机它不仅装订速度快为我们大大的节约时间、而且没有噪音、无污染,下面看具体操作步骤:财务凭证装订机用法——热熔管财务装订机操作步骤:财务凭证装订机用法 1、接通电源后,插入装订管财务凭

护发素的用法 护发素发膜的正确用法

护发素的用法——简介护发素可以为头发提供一层保护,或许就因此得名了吧。比起洗发用品,护发素能够令头发看起来更自然和健康。 下面来介绍一下护发素的用法供参考。 护发素的用法——工具/原料护发素护发素的用法——方法/步骤护发

声明:《beginthreadex例子 beginthreadex用法》为网友河畔三分沉酣分享!如侵犯到您的合法权益请联系我们删除