2 ms·
I think it depends on the language. What you say is true for JS because it's single threaded but .Net has a thread pool, that means that you can have concurrent
by pmoleri 4y ago
I think it depends on the language. What you say is true for JS because it's single threaded but .Net has a thread pool, that means that you can have concurrent and even parallel tasks attending different events from your single thread UI.
- jayd16 4y agoYou cannot use a single UI thread in a parallel way. Its a contradictory statement. Parallel is the opposite of single threaded. C# does have a thread pool that you can use with async/await with multiple threads but that would be different from a UI thread or its synchronization context.
- pmoleri 4y agoIt's not contradictory, the UI is single threaded but on the dispatched events you can perfectly have long running tasks that can perform parallel work and affefct common memory. It's also my understanding that if you stick to async/await and don't create your own tasks, the synchronization context will be the one of the UI thread thus never run in parallel. However, this doesn't prevent you from doing so.
- jayd16 4y agoAh I see what you mean. Sure, you can do that if you desire. My point was simply that the system allows you to not do that. It's easy to get concurrency without parallelism. And it's also easy to get parallelism. But yes, In C# you're only guarded by self control and the slightly cumbersome calls it takes to jump threading context. It's not hard to stay in a single context but it's not enforced.
- gpderetta 4y agoBut you can do the same with threads: pin them to a single cpu/scheduler and use a non-preemptive scheduling strategy. At some point you realize that explicit continuation passing, threads, coroutines and async/await are all the same thing, and the only thing that async/await gives you is a static bound on your suspended stack size (by enforcing suspension of a single activation frame).