我采用临界区的线程同步方式进行了线程同步,方法如下:// 临界区结构对象
CRITICAL_SECTION g_cs;
//全局共享变量
list<CRecord> stList;//启动线程前进行初始化临界区
InitializeCriticalSection(&g_cs);在线程中:
CRecord stRec;
stRec.id = id;
// 进入临界区
EnterCriticalSection(&g_cs);
stList.push_back(stRec);
// 离开临界区
LeaveCriticalSection(&g_cs);在不用到共享变量的地方释放临界区:
DeleteCriticalSection( &g_cs);编译结果为:
函数InitializeCriticalSection错误为:
Unicode identifiers are not yet supported
undeclared identifier
error : missing ';' before identifier 'InitializeCriticalSection'函数EnterCriticalSection错误为:
Unicode identifiers are not yet supported
syntax error : missing ';' before identifier 'EnterCriticalSection'
identifier not found, even with argument-dependent lookup函数LeaveCriticalSection错误为:
Unicode identifiers are not yet supported
syntax error : missing ';' before identifier 'LeaveCriticalSection'
identifier not found, even with argument-dependent lookup函数DeleteCriticalSection编译通过。我使用的编译环境为vc.net2003!

解决方案 »

  1.   

    我发现出现上述原因是我在线程函数中调用了一个一般的函数,而我在这个一般的函数中使用了这两个函数:
    EnterCriticalSection和LeaveCriticalSection
    就有问题了;
    如果我在这个一般的函数中有对全局变量的操作怎么实现同步呢?
    注明:这个一般的函数是在线程函数中调用的!
      

  2.   

    有全角字符,可能为全角空格,在VC下按ctrl+shift+8 显示空格和Tab,如果发现某处空白巴它删了(不是指没有字符的地方)就好了