From d17fe4b039de8e1dca65c1422e009690346cc7e3 Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sat, 19 Dec 2015 16:58:08 +0100 Subject: [PATCH] Fix: access to _AcInstanceLocks was not threadsafe --- Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs b/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs index 08d908c3..91d4e4e1 100644 --- a/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs +++ b/Vocaluxe/Lib/Video/Acinerella/CAcinerella.cs @@ -192,17 +192,23 @@ namespace Vocaluxe.Lib.Video.Acinerella #endif private static readonly Object _Lock = new Object(); + private static readonly Object _DictionaryLock = new Object(); private static readonly Dictionary _AcInstanceLocks = new Dictionary(20); private static object _GetLockToken(IntPtr pAcDecoder) { - object l = null; - _AcInstanceLocks.TryGetValue(pAcDecoder.ToInt64(), out l); - if (l == null) + object l; + + lock (_DictionaryLock) { - l = new object(); - _AcInstanceLocks.Add(pAcDecoder.ToInt64(), l); + _AcInstanceLocks.TryGetValue(pAcDecoder.ToInt64(), out l); + if (l == null) + { + l = new object(); + _AcInstanceLocks.Add(pAcDecoder.ToInt64(), l); + } } + return l; }