注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

mie

 
 
 

日志

 
 

VC 2010编译错误:error C3861: “InterlockedIncrement16”: 找不到标识符  

2010-12-07 18:57:24|  分类: 编译错误 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

VC 2010编译错误:error C3861: “InterlockedIncrement16”: 找不到标识符

 

InterlockedIncrement16宏是在winnt里面声明的。但是 #include <winnt.h>之后,问题仍然存在!

 

于是MSDN 2010,MSDN 2010 给出了下面的例子:

The Win32 function is declared in Wdm.h or Ntddk.h.

These routines are only available as intrinsics.

Example

For a sample of how to use _InterlockedIncrement, see _InterlockedDecrement.

 

// compiler_intrinsics_interlocked.cpp  // compile with: /Oi  #define _CRT_RAND_S    #include <cstdlib>  #include <cstdio>  #include <process.h>  #include <windows.h>    // To declare an interlocked function for use as an intrinsic,  // include intrin.h and put the function in a #pragma intrinsic   // statement.  #include <intrin.h>    #pragma intrinsic (_InterlockedIncrement)    // Data to protect with the interlocked functions.  volatile LONG data = 1;    void __cdecl SimpleThread(void* pParam);    const int THREAD_COUNT = 6;    int main() {     DWORD num;     HANDLE threads[THREAD_COUNT];     int args[THREAD_COUNT];     int i;       for (i = 0; i < THREAD_COUNT; i++) {       args[i] = i + 1;       threads[i] = reinterpret_cast<HANDLE>(_beginthread(SimpleThread, 0,                              args + i));        if (threads[i] == reinterpret_cast<HANDLE>(-1))           // error creating threads           break;     }       WaitForMultipleObjects(i, threads, true, INFINITE);  }    // Code for our simple thread  void __cdecl SimpleThread(void* pParam) {     int threadNum = *((int*)pParam);     int counter;     unsigned int randomValue;     unsigned int time;     errno_t err = rand_s(&randomValue);       if (err == 0) {        time = (unsigned int) ((double) randomValue / (double) UINT_MAX * 500);        while (data < 100) {           if (data < 100) {              _InterlockedIncrement(&data);              printf_s("Thread %d: %d\n", threadNum, data);           }             Sleep(time);   // wait up to half of a second        }     }       printf_s("Thread %d complete: %d\n", threadNum, data);  }  
于是,
#define _CRT_RAND_S

#include <cstdlib>
#include <cstdio>
#include <process.h>
#include <windows.h>

#include <intrin.h>
#pragma intrinsic (_InterlockedIncrement)
#pragma intrinsic (_InterlockedIncrement16)
还是一样!
 
只能这样了:
InterlockedIncrement((LONG *)&g_id);
 
By:zhanyonhu
 
  评论这张
 
阅读(3474)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016