#include <stdio.h> #include <windows.h> #include <process.h> DWORD count = 0; bool lock = FALSE; //TS指令 bool TS(bool *lock) { bool old; old = *lock; *lock = TRUE; return old; } void countproc(void *) { do { while(TS(&lock)); count++; printf("count:%d\n",count); //释放 lock = FALSE; }while(1); _endthread(); } int main(void) { for(int i=0;i<2;i++) _beginthread(countproc,0,NULL); while(getchar() != 'q') ; return 0; }
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课