Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyClass
- {
- private object m_Locker = new object();
- private Dicionary<string, object> m_Hash = new Dictionary<string, object>();
- public void OptionA()
- {
- lock(m_Locker){
- // Do something with the dictionary
- }
- }
- public void OptionB()
- {
- lock(m_Hash){
- // Do something with the dictionary
- }
- }
- }
- lock (m_Hash)
- {
- // Across all threads, I can be in one and only one of these two blocks
- // Do something with the dictionary
- }
- lock (m_Hash)
- {
- // Across all threads, I can be in one and only one of these two blocks
- // Do something with the dictionary
- }
- private object m_LockerA = new object();
- private object m_LockerB = new object();
- lock (m_LockerA)
- {
- // It's possible this block is active in one thread
- // while the block below is active in another
- // Do something with the dictionary
- }
- lock (m_LockerB)
- {
- // It's possible this block is active in one thread
- // while the block above is active in another
- // Do something with the dictionary
- }
Add Comment
Please, Sign In to add comment