Skip to content

Commit faba965

Browse files
madelsoncarlossanlop
authored andcommitted
Implement feedback from #75054
1 parent 478b697 commit faba965

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ public DictionaryEntry Entry
11081108
object? value = null;
11091109
// Lock the cache first, then the reader (in this case, we don't actually need to lock the reader and cache at the same time).
11101110
// Lock order MUST match RuntimeResourceSet.GetObject to avoid deadlock.
1111+
Debug.Assert(!Monitor.IsEntered(_reader));
11111112
lock (_reader._resCache)
11121113
{
11131114
if (_reader._resCache.TryGetValue(key, out ResourceLocator locator))

src/libraries/System.Private.CoreLib/src/System/Resources/RuntimeResourceSet.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Diagnostics;
77
using System.IO;
8+
using System.Threading;
89

910
namespace System.Resources
1011
#if RESOURCES_EXTENSIONS
@@ -285,6 +286,7 @@ private IDictionaryEnumerator GetEnumeratorHelper()
285286

286287
// Lock the cache first, then the reader (reader locks implicitly through its methods).
287288
// Lock order MUST match ResourceReader.ResourceEnumerator.Entry to avoid deadlock.
289+
Debug.Assert(!Monitor.IsEntered(reader));
288290
lock (cache)
289291
{
290292
// Find the offset within the data section

src/libraries/System.Resources.Extensions/tests/BinaryResourceWriterUnitTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ public static void EmbeddedResourcesAreUpToDate()
501501
}
502502
}
503503

504-
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))]
505504
/// <summary>
506505
/// This test has multiple threads simultaneously loop over the keys of a moderately-sized resx using
507506
/// <see cref="ResourceManager"/> and call <see cref="ResourceManager.GetString(string)"/> for each key.
@@ -515,6 +514,7 @@ public static void EmbeddedResourcesAreUpToDate()
515514
/// Whether to use <see cref="IDictionaryEnumerator.Entry"/> vs. <see cref="IDictionaryEnumerator.Key"/> when enumerating;
516515
/// these follow fairly different code paths.
517516
/// </param>]
517+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))]
518518
[InlineData(false)]
519519
[InlineData(true)]
520520
public static void TestResourceManagerIsSafeForConcurrentAccessAndEnumeration(bool useEnumeratorEntry)

src/libraries/System.Resources.ResourceManager/tests/ResourceManagerTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,15 @@ public static void TestResourceManagerIsSafeForConcurrentAccessAndEnumeration(bo
247247

248248
const int Threads = 10;
249249
using Barrier barrier = new(Threads);
250-
Task task = Task.WhenAll(Enumerable.Range(0, Threads).Select(_ => Task.Run(WaitForBarrierThenEnumerateResources)));
251-
252-
Assert.True(task.Wait(TimeSpan.FromSeconds(10)));
250+
Task[] tasks = Enumerable.Range(0, Threads)
251+
.Select(_ => Task.Factory.StartNew(
252+
WaitForBarrierThenEnumerateResources,
253+
CancellationToken.None,
254+
TaskCreationOptions.LongRunning,
255+
TaskScheduler.Default))
256+
.ToArray();
257+
258+
Assert.True(Task.WaitAll(tasks, TimeSpan.FromSeconds(30)));
253259

254260
void WaitForBarrierThenEnumerateResources()
255261
{

0 commit comments

Comments
 (0)