seqlock 實在是非常好用的概念 , 假設你有兩個 threads ,
一個要寫入結構資料,一個要讀結構資料,此時,最常用的方法是 mutex or spin lock ,
可以使用 seqlock 作到 lock-free !!
在 structure 裡面加上 int seqno ,
Thread1 :
++seqno ;
writeinstruc();
++seqno ;
Thread2 :
while(1)
{
ix1 = seqno ;
if ( (ix1%2)==1)
continue ;
ReadStru();
ix2 = seqno ;
if(ix1 == ix2)
break ;
}
使用在 intel , amd cpu 無須處理 memory barrier 問題 ,
全站熱搜
留言列表