您的位置:首页 > 其它

data race check with valgrind

2015-11-25 22:27 225 查看
http://valgrind.org/docs/manual/hg-manual.html

/*
* gcc t.c -o t -g -lpthread
* valgrind --tool=helgrind ./t
*/

#include <pthread.h>

int var = 0;

void* child_fn ( void* arg ) {
var++; /* Unprotected relative to parent */ /* this is line 6 */
return NULL;
}

int main ( void ) {
pthread_t child;
pthread_create(&child, NULL, child_fn, NULL);
var++; /* Unprotected relative to child */ /* this is line 13 */
pthread_join(child, NULL);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: