multithread 中static物件使用心得

  • 657
  • 0

摘要:multithread 中static物件使用心得

ensure the the function which use static object doesn't share between 2 threads...it is quit possible occur problems....

以前很懶常常在字串轉換的function裡面使用static的東西...

結果多執行緒執行起來發現讀不到物件的情形...

找了老半天找不到問題...結果發現原來字串轉換的時候被另一個執行緒把結果變換走了...

本來要的結果是"AAA"轉成L"AAA"

但是另一個thread就那麼剛好也用到這字串轉換...真是臨老穆卡賀哩...

結果AAA就變成了L"BBB"

然後就找不到資源導致當機了...真是臨老穆卡賀哩