我正在爲一個學校的java項目工作,你必須處理一個多線程程序。 我需要一個類,多線程之間共享,基本上是有管理的併發訪問值的矩陣,它看起來是這樣的: public class CacheMatrix{
private MyType[][] cachedItems;
public CacheMatrix(int size){
this.cachedItems = new MyType[
請考慮比較並交換了下面的一段代碼,讓我知道爲什麼這個原子指令是比原子檢查並設置更強大,作爲一個互斥原始? char CompareAndSwap(int *ptr, int old, int new) {
unsigned char ret;
// Note that sete sets a ’byte’ not the word
__asm__ __volatile__ (
" lock\