From 64a7ab3e5a1a75668652beb7a11904541ebbca1d Mon Sep 17 00:00:00 2001 From: Hitesh Madan Date: Mon, 2 Dec 2019 14:37:48 -0800 Subject: [PATCH] reset ownership if handle creation fails --- cs/src/core/Device/FixedPool.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cs/src/core/Device/FixedPool.cs b/cs/src/core/Device/FixedPool.cs index 522cc2205..0242dda97 100644 --- a/cs/src/core/Device/FixedPool.cs +++ b/cs/src/core/Device/FixedPool.cs @@ -26,7 +26,7 @@ public FixedPool(int size, Func creator) { while (true) { - for (int i=0; i creator) { if (Interlocked.CompareExchange(ref owners[i], 2, val) == val) { - items[i] = creator(); + try + { + items[i] = creator(); + } + catch + { + Interlocked.Exchange(ref owners[i], val); + throw; + } + return (items[i], i); } }