3 ms·
>You really don't need to know all that to do parallel programming, and if you ever are using any significant number of those in one program, you're going to be
by cerebellum42 7y ago
>You really don't need to know all that to do parallel programming, and if you ever are using any significant number of those in one program, you're going to be in a world of pain.
I don't entirely disagree, but most environments (or "paradigms") simply hide all that away from the user. Which is generally a good thing. Chances are you _are_ using a lot of those primitives in any given parallel or concurrent program, but you're only aware of one or two of them. For example, a channel for message passing between threads (or tasks in a cooperative multitasking context) might contain a Semaphore and an atomic reference counted pointer which in turn contains atomic integers. See [0] for an example.
And while concurrency and parallelism are not the same thing, you often end up having to consider the same synchronization problems in your code whether it's concurrent or parallel. Cooperative multitasking does involve true parallelism when the scheduler uses multiple threads on a processor with multiple cores. Code is not just being executed concurrently there, it is (possibly, not guaranteed to be fair) executed in parallel.
[0] https://docs.rs/crate/tokio/0.2.9/source/src/sync/mpsc/chan.rs https://docs.rs/crate/tokio/0.2.9/source/src/sync/mpsc/chan....
- kerkeslager 7y ago> Chances are you _are_ using a lot of those primitives in any given parallel or concurrent program, but you're only aware of one or two of them. Okay, but I think it's fairly clear from context that "using" in my post meant "directly using" or "using in such a way that you have to understand how they work". There are a bunch of ways Erlang's message queues could work, but I don't need to know which way they work. If they work with locks you could say I'm using locks, but that's clearly not the point of what I'm saying. > And while concurrency and parallelism are not the same thing, you often end up having to consider the same synchronization problems in your code whether it's concurrent or parallel. Often, sure. But also, often not, which is why I said "it's quite possible that you've never written a line of parallel code."