When a benchmark returns a ValueTask, it is simply called with .GetAwaiter().GetResult().
This is illegal ValueTask usage: you must not call GetResult() until the task has been completed.
IValueTaskSource-backed tasks do not need to support blocking on GetResult(). The in-box ManualResetValueTaskSourceCore does not support blocking GetResult(). Nor does the DOTNET_SYSTEM_THREADING_POOLASYNCVALUETASKS feature in .NET 5.
Instead, the ValueTask should be converted to a Task first:
static void BlockForResult(ValueTask task)
{
if (task.IsCompleted)
task.GetAwaiter().GetResult();
else
task.AsTask().GetAwaiter().GetResult();
}
(This will be unfortunate for the memory diagnoser, as a bogus Task will show up, but the alternative is to just crash...)
When a benchmark returns a
ValueTask, it is simply called with.GetAwaiter().GetResult().This is illegal
ValueTaskusage: you must not callGetResult()until the task has been completed.IValueTaskSource-backed tasks do not need to support blocking onGetResult(). The in-boxManualResetValueTaskSourceCoredoes not support blockingGetResult(). Nor does theDOTNET_SYSTEM_THREADING_POOLASYNCVALUETASKSfeature in .NET 5.Instead, the
ValueTaskshould be converted to aTaskfirst:(This will be unfortunate for the memory diagnoser, as a bogus
Taskwill show up, but the alternative is to just crash...)