0
下面的代碼是否安全,多線程正在訪問屬性但不寫入特定對象。新對象正在創建和分配。多線程調用CreateXmlDoc
和ReadXmlDoc
鎖定屬性獲取/設置
public class DataHolder
{
public XmlDocument XmlDoc {get; set;}
}
public class AccessClass
{
DataHolder dataHolderInstance;
public AccessClass(DataHolder _dataHolder)
{
dataHolderInstance = _dataHolder;
}
private void CreateXmlDoc()
{
XmlDocument _xmlDoc = new XmlDocument();
dataHolderInstance.XmlDoc = _xmlDoc;
}
private void ReadXmlDoc()
{
XmlNodeList elemList = dataHolderInstance.XmlDoc.GetElementsByTagName("title");
}
}
在訪問類中初始化數據持有者實例在哪裏?它是否在訪問類之間共享? – Rup 2014-10-05 21:52:22
請更改。多個線程調用'CreateXmlDoc'嗎?如果是這樣,那麼不,它不是線程安全的。 – 2014-10-05 21:52:29
@SimonWhitehead是多線程調用'CreateXmlDoc' – swiftcode 2014-10-05 22:02:48