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值)。 是否有任何竞争条件可能导致读者和作者试图访问同一个插槽?