电玩城打鱼捕鱼-专业24小时上下分

volaitle关键字

十二月 21st, 2019  |  电玩城捕鱼系统简介

#includecstdlib#includecstdio#includeiostream#includepthread.h#includeunistd.husingnamespacestd;boolSentinel=true;intCriticalData=0;void*ThreadFunc1(void*pArguments){while(Sentinel)sleep(0);//volatilespinlock//CriticalDataloadguaranteedaftereveryloadofSentinelcout"CriticalData="CriticalDataendl;returnEXIT_SUCCESS;}void*ThreadFunc2(void*pArguments){sleep(10);cout"threadfun2"endl;CriticalData++;//guaranteedtooccurbeforewritetoSentinelSentinel=false;//exitcriticalsectionreturnEXIT_SUCCESS;}intmain(){pthread_tpt1,pt2;pthread_create(pt1,NULL,ThreadFunc1,NULL);pthread_create(pt2,NULL,ThreadFunc2,NULL);pthread_join(pt1,NULL);pthread_join(pt2,NULL);returnEXIT_SUCCESS;}

boolSentinel=true;这句代码前面,加与不加,似乎没有明显差异!!!!

标签:, , , ,

Your Comments

近期评论

    功能


    网站地图xml地图