https://docs.microsoft.com/en-us/aspnet/core/blazor/components?view=aspnetcore-3.1#invoke-component-methods-externally-to-update-state
In the first sentence of this section it states "Blazor uses a SynchronizationContext to enforce a single logical thread of execution."
The use of the word "thread" can be confusing to people whose first language is not English as it can be confused/mistaken for meaning an actual "Thread" as in Threading.Thread.
Perhaps the word "unit" would help avoid confusion?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Thanks for your feedback, @SQL-MisterMagoo.
At this point we would like to stick with current wording. If we hard more feedback similar to this, we will reword it then.
The words "thread" and "execution" do suggest a Thread.
May I suggest use of the word "chain" instead? Or say it uses an ExecutionContext to ensure the component isn't used by more than one thread at a time?
@mrpmorris I like your suggestion regarding chain.
I even think flow would be another option (@SQL-MisterMagoo I couldn't come up with something earlier, but I think these are good alternatives).
@danroth27 thoughts?
I prefer chain. A flow is a process that could be followed by multiple threads, a chain is a single thing made up of linked parts. That's how my simpleton mind works anyway :)
If you used both parts of my suggestion it would be 100% indisputably clear that it means any thread but only one at a time, resulting in a single chain of execution.
Thus far ...
Current:
Blazor uses a SynchronizationContext to enforce a single logical thread of execution.
Suggestion:
Blazor uses a SynchronizationContext to enforce a single logical chain of execution.
From @pranavkm: Blazor Server's sync context attempts to emulate a single threaded environment so that it closely matches the browser \ WebAssembly's model which is single threaded. At any given point of time, work is performed on exactly one thread giving the impression of a single logical thread. No two operations execute concurrently.
So, I think the use of the word "thread" here is deliberate and important.
@danroth27 The text you wrote is perfect. I can't find it on that page though. If the text on that page was as clear as the text you quoted it would be spot on!
@danroth27 @pranavkm It was my original assumption that it was a real thread, that @SQL-MisterMagoo was so kind as to report for me.
By assuming that it was a real thread I also assumed that the managed thread ids would be equal and ThreadLocal would work. In retrospect I could have known that the synchronizationcontext would only guard against multiple render tasks being executed on the thread pool at the same time. It's way more efficient.
However, it was not clear to me when I read the documentation the first time. Judging by the number of questions about threading / invoke on the gitter channel and the number of answers that say that you have to Invoke state changes on the "render thread", it might be a good idea to clarify in the docs that it's a context, not a real thread and that, equal to aspnetcore itself, a "render" task might end up on any threadpool thread, just not two at the same time.
Thank you!