-
Notifications
You must be signed in to change notification settings - Fork 5.3k
A few fixes in the threadpool semaphore. Unify Windows/Unix implementation of LIFO policy. #123921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
261210d
A few fixes in the threadpool semaphore. Unify Windows/Unix implement…
VSadov 2a07e58
Apply suggestions from code review
VSadov cc8092a
Apply suggestions from code review
VSadov 4b92449
comment
VSadov dc1a4e6
Typo: counted current thread as active twice.
VSadov afd874d
limit acceptable values of ThreadPool_UnfairSemaphoreSpinLimit
VSadov 1630e9f
fix OSX and FreeBSD builds.
VSadov a8c5ab9
suppress unused-parameter in placeholders
VSadov 62a3d0b
suppress missing-noreturn in placeholders
VSadov e5b0f28
futex timeout is relative by default
VSadov 8a52a38
relaxed an assert.
VSadov b7c44fb
fix Linux x86 build
VSadov 8f70ad7
Added assert in ~LowLevelThreadBlocker() as in other similar finalizers.
VSadov 134381f
assert that _pendingSignals is not too large.
VSadov 73af91f
idempotent Dispose
VSadov 5853342
Update src/libraries/System.Private.CoreLib/src/System/Threading/LowL…
VSadov 9b78e16
some more PR feedback
VSadov 1a74f00
more feedback
VSadov 4be373d
PR feedback (Mincore)
VSadov c49c135
add Synchronization.lib to native libs
VSadov 3994f31
Unused Usings
VSadov bbfae6d
avoid extremely unlikely int overflow
VSadov 793ec96
Add Synchronization.lib to NAOT repro project.
VSadov dd61a6b
separate the new manually introduced entries in WindowsAPI.txt
VSadov 13d7a70
remove SuppressGCTransition on waking APIs
VSadov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/libraries/Common/src/Interop/Unix/System.Native/Interop.Futex.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
|
|
||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Sys | ||
| { | ||
| [LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_LowLevelFutex_WaitOnAddress")] | ||
| internal static unsafe partial void LowLevelFutex_WaitOnAddress(int* address, int comparand); | ||
|
|
||
| [LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_LowLevelFutex_WaitOnAddressTimeout")] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| internal static unsafe partial bool LowLevelFutex_WaitOnAddressTimeout(int* address, int comparand, int timeoutMilliseconds); | ||
|
|
||
| [LibraryImport(Libraries.SystemNative, EntryPoint = "SystemNative_LowLevelFutex_WakeByAddressSingle")] | ||
| internal static unsafe partial void LowLevelFutex_WakeByAddressSingle(int* address); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/libraries/Common/src/Interop/Windows/Mincore/Interop.WaitOnAddress.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
|
|
||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Mincore | ||
| { | ||
| [LibraryImport(Libraries.Synch, SetLastError = true)] | ||
| internal static unsafe partial BOOL WaitOnAddress(void* Address, void* CompareAddress, nint AddressSize, int dwMilliseconds); | ||
VSadov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [LibraryImport(Libraries.Synch)] | ||
| internal static unsafe partial void WakeByAddressSingle(void* Address); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelFutex.Unix.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
|
|
||
|
|
||
| namespace System.Threading | ||
| { | ||
| // NOTE: Only supported on Linux for now. | ||
| // Most OS have support for futex-like APIs and should be added in the future. | ||
| // (ex: OSX has `os_sync_wait_on_address`, but support may vary by OS version) | ||
|
|
||
| /// <summary> | ||
| /// A compare-and-wait synchronization primitive. | ||
| /// Provides simple functionality to block and wake threads. | ||
| /// </summary> | ||
| internal static unsafe class LowLevelFutex | ||
| { | ||
| internal static void WaitOnAddress(int* address, int comparand) | ||
| { | ||
| Interop.Sys.LowLevelFutex_WaitOnAddress(address, comparand); | ||
| } | ||
|
|
||
| internal static bool WaitOnAddressTimeout(int* address, int comparand, int milliseconds) | ||
| { | ||
| Debug.Assert(milliseconds >= -1); | ||
| if (milliseconds == -1) | ||
| { | ||
| WaitOnAddress(address, comparand); | ||
| return true; | ||
| } | ||
|
|
||
| return Interop.Sys.LowLevelFutex_WaitOnAddressTimeout(address, comparand, milliseconds); | ||
| } | ||
|
|
||
| internal static void WakeByAddressSingle(int* address) | ||
| { | ||
| Interop.Sys.LowLevelFutex_WakeByAddressSingle(address); | ||
| } | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelFutex.Windows.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace System.Threading | ||
| { | ||
| /// <summary> | ||
| /// A compare-and-wait synchronization primitive. | ||
| /// Provides simple functionality to block and wake threads. | ||
| /// </summary> | ||
| internal static unsafe class LowLevelFutex | ||
| { | ||
| internal static void WaitOnAddress(int* address, int comparand) | ||
| { | ||
| Interop.BOOL result = Interop.Mincore.WaitOnAddress(address, &comparand, sizeof(int), -1); | ||
| // assert success, but in release treat unexpected results as spurious wakes | ||
| Debug.Assert(result == Interop.BOOL.TRUE); | ||
| } | ||
|
|
||
| internal static bool WaitOnAddressTimeout(int* address, int comparand, int milliseconds) | ||
| { | ||
| Interop.BOOL result = Interop.Mincore.WaitOnAddress(address, &comparand, sizeof(int), milliseconds); | ||
| if (result == Interop.BOOL.TRUE) | ||
| { | ||
| // normal or spurious wake | ||
| return true; | ||
| } | ||
|
|
||
| int lastError = Marshal.GetLastWin32Error(); | ||
| Debug.Assert(lastError == Interop.Errors.ERROR_TIMEOUT); | ||
| if (lastError == Interop.Errors.ERROR_TIMEOUT) | ||
| { | ||
| // timeout | ||
| return false; | ||
| } | ||
|
|
||
| // in release treat unexpected results as spurious wakes | ||
| return true; | ||
| } | ||
VSadov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| internal static void WakeByAddressSingle(int* address) | ||
| { | ||
| Interop.Mincore.WakeByAddressSingle(address); | ||
| } | ||
| } | ||
| } | ||
37 changes: 0 additions & 37 deletions
37
src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Unix.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.