1.临界区

#include <windows.h>

CRITICAL_SECTION logSection1;

InitializeCriticalSection(&logSection1);

 

EnterCriticalSection(&logSection1); //加锁,防止一起写文件

/*...*/

LeaveCriticalSection(&logSection2);

 

DeleteCriticalSection(&logSection1);

2.多媒体定时器

首先在项目的属性里,链接器->输入中加入该库:winmm.lib

#include "windows.h"
#include "mmsystem.h"

UINT timehandle;
//每1min调用一次时间处理函数,清理30天过期的数据
if((timehandle = timeSetEvent(60*1000, 1,
(LPTIMECALLBACK)TimeProc, // 回调函数;
0, // 用户传送到回调函数的数据;
TIME_PERIODIC)) == 0)//周期调用定时处理函数;
{
LogErrors("Fail to set Timer!");
}

//声明成回调函数

void CALLBACK TimeProc(UINT wTimerID, UINT msg,DWORD dwUser,DWORD dwl,DWORD dw2); 

//使用时

void CALLBACK TimeProc(UINT wTimerID, UINT msg,DWORD dwUser,DWORD dwl,DWORD dw2)

{.........}

//该多媒体定时器,时间不能太多,周期设置为1h会失败。。

3.线程

#include <windows.h>

#include <process.h>//_beginthread _endthread

int cameraid[CAMERA_EXIST];
for(int i=0;i<CAMERA_EXIST;i++)
{
cameraid[i]=i;
_beginthread(ComThreadProcess,0,&cameraid[i]); //!!!!!!!不能直接在循环中用&i,因为,i的值是临时的,当循环退出后,i就不存在了
}

_endthread();//线程退出时自动调用

//线程函数

void ComThreadProcess(void* arg)

{...........}

posted on 2012-09-07 20:32  particle  阅读(532)  评论(0编辑  收藏  举报