Tag: 竞争条件

读/写器伪代码中竞争条件的可能性

我正在分析以下关于竞争条件的伪代码(一些自我练习)并查看可能性的位置。 伪代码描述了一个模糊的异步读写器。 作家线程 r = 0; w = 1; l = 2; //assign start slot numbers while(1) { write_slot(w); l = w; //last written slot is ww = not(r,l) //assigns next slot so that w is neither r or l } 读者主题 while(1) { r = l; //read from latest write read(r); } 到目前为止我发现的腐败/竞争条件的可能性是,如果变量读/写不是primefaces的,那么,例如,当读者读到它时,作者可以改变l的值(可能导致通过撕裂读/写的无意义的r值)。 是否有任何竞争条件可能导致读者和作者试图访问同一个插槽?

使用pthreads进行条件等待

我似乎正在使用pthreads条件变量运行可能的死锁。 这是代码 thread function(){ for (condition){ do work /* should the thread continue? */ if (exit == 1){ break; /* exit for */ } } /* end for */ pthread_mutex_lock(&mtxExit); exit = 0; pthread_cond_signal(&condVar); pthread_mutex_unlock(&mtxExit); } 主要function如下: function main(){ if (thread is still active){ pthread_mutex_lock(&mtxExit); exit = 1; pthread_mutex_unlock(&mtxExit); } /* end if */ while […]

分段错误p_thread可能存在竞争条件

问题:我创建了一个子线程TIDS的链接列表,并希望在继续主线程之前等待所有子tid完成执行。 基本上我有目录遍历(目录由给定struct的成员指定)。 每当我看到一个目录或文件时,我都会创建一个新线程并将其threadID放入链表中。 但是,当我遍历链表并调用pthread_join我得到一个分段错误(核心转储) – 我无法理解为什么。 我相信可能与种族状况有关,但我不确定。 当我删除pthread_join我不再是段错误但是我没有完全遍历目录中的目录。 程序: void *handy(void *arguments) { static pthread_t threadA; threadA=pthread_self(); handarg *thestruct=(handarg*)arguments; DIR *dp=opendir(thestruct->directory); DIR *outExist=opendir(thestruct->outputdirectory); if(outExist==NULL) { if((thestruct->outputdirectory = “”)) { ; } else { printf(“The outputdirectory doesnt exist, program terminated\n”); exit(1); } } struct dirent *entry; // has two important members (d-type)-tells me if its a […]

x86上的竞争条件

有人可以解释这个说法: shared variables x = 0, y = 0 Core 1 Core 2 x = 1; y = 1; r1 = y; r2 = x; 如何在x86处理器上使用r1 == 0和r2 == 0 ? 来自Bartosz Milewski的“并发语言” 。