5 ms·
The morning paper had a nice set of blog posts about this: Why they're equivalent (duals): https://blog.acolyer.org/2014/12/08/on-the-duality-of-operating-syst
by skybrian 9y ago
The morning paper had a nice set of blog posts about this:
Why they're equivalent (duals):
https://blog.acolyer.org/2014/12/08/on-the-duality-of-operating-system-structures/ https://blog.acolyer.org/2014/12/08/on-the-duality-of-operat...
Why threads are a bad idea:
https://blog.acolyer.org/2014/12/09/why-threads-are-a-bad-idea/ https://blog.acolyer.org/2014/12/09/why-threads-are-a-bad-id...
Why events are a bad idea:
https://blog.acolyer.org/2014/12/10/why-events-are-a-bad-idea/ https://blog.acolyer.org/2014/12/10/why-events-are-a-bad-ide...
Unifying events and threads (in Haskell):
https://blog.acolyer.org/2014/12/11/a-language-based-approach-to-unifying-events-and-threads/ https://blog.acolyer.org/2014/12/11/a-language-based-approac...
Unifying events and treads (in Scala):
https://blog.acolyer.org/2014/12/12/scala-actors-unifying-thread-based-and-event-based-programming/ https://blog.acolyer.org/2014/12/12/scala-actors-unifying-th...
- i_feel_great 9y agoAnother great read on threads: The Problem with Threads, by Edward Lee: https://www2.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf https://www2.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-....
- MichaelMoser123 9y agohe doesn't seem to have mentioned cooperative threads/green threads/non preemptive threads in this series http://wiki.c2.com/?CooperativeThreading http://wiki.c2.com/?CooperativeThreading They are easier to program than events, they still have problems like its easy to run out of a very limited stack and you have to yield your cooperative thread often to other tasks, but they are easier to maintain than a state machine (that is often done as a very big switch statement).
- Waterluvian 9y agoI'm using greenlets via gevent to handle a system that interacts with a number of http APIs, exposes an RPC API and has a data processing loop. I absolutely love the concurrency model. For cpu bound processes and short API timeouts, getting to control when my "threads" yield makes it very easy to avoid the common threading pitfalls. It also means my application can remain very simple. Ie. I don't need to think about things like Celery or Redis or handling locking meticulously.
- veli_joza 9y agoThe cooperative multitasking is mentioned in "Why events are a bad idea" as a counter-argument #3. They are considered under threads category. It's unfortunate that only some languages support them.
- MichaelMoser123 9y ago> It's unfortunate that only some languages support them. yes, you need runtime support for this feature. If it is impossible to change the runtime than it can't be done for the language; now the runtime may have problem to work with a very limited stack for example, or the runtime is big and difficult to change (like the JVM), or it has long library functions that cannot yield to other co threads. However C/C++ or other languages that do not sit on top of a big runtime dont have that problem.
- tiagobraw 9y agoThere's also this nice paper on this topic (unifying events and threads): http://salmito.com/papers/rb-resd2011/ http://salmito.com/papers/rb-resd2011/
- Matthias247 9y agoDuring the last 5 years where I wrote LOTS of concurrent code I was in various thought stages, where in each stage I had some different feeling of what the best model might be. In the meantime I have the feeling that both threaded and single-threaded event-driven programming programming models work well, and that the main thing to avoid is mixing both. E.g. I found that using callback based or push-style APIs (like Reactive Extensions) in multithreaded environments is not a great idea, since it often won't be obvious on which thread a callback will be running and which kind of synchronization is needed. Not using callbacks and instead waiting/blocking for results works better. In a pure singlethreaded environment it's generally easy to know what to expect from a callback or promise - it will be fulfilled from the same thread and the continuation will also run from the same thread. In a multithreaded environment it can get hard - e.g. a promise continuation (like Task.ContinueWith() in C#) could run in any thread depending on the setup. And blocking on promises (like with Task.Result) may be valid in some situations (where the Promise is fulfilled from another thread) but not in others (where the Promise is fulfilled from the same thread). Using only synchronous primitives in multithreaded environments (like it's common in Go) avoids these pitfalls and questions. Sometimes having a singlethreaded eventloop even in multithreaded environment however makes sense, like e.g. for GUIs (and other applications which have lots of shared state). In that case it should be assured that all objects which are living on the eventloop should just be accessed from other objects on the same thread - and do not involved directly in function calls from other threads. If that's required posting events or function calls to the eventloop thread is a much saner approach then trying to add low-level multithreading synchronization primitives everywhere.