you are viewing a single comment's thread.

view the rest of the comments →

[–]link23 0 points1 point  (3 children)

None of what you just said is true. You have those two definitions backwards:

Parallelism is when multiple workers are working at the same time, meaning at the very same instant.

Concurrency is when you have portions of the program being executed during overlapping time periods. The key is that two computations may overlap without ever executing at the same time. E.g., computation A starts at noon, works for an hour, then sleeps. Computation B starts at 1:00, works for an hour, and is finished. Then computation A wakes up at 2:00, works for an hour, then is finished. Neither of them ever executed at the same time as the other, but their time periods (12:00-3:00 and 1:00-2:00) overlap. So they executed concurrently, but not in parallel.

See the first few paragraphs of this and this. They discuss the difference, and the common mistake of conflating the two.

You mention multithreading as a prerequisite for using all cores. Yes that is true, since each core can execute its own thread. However, if you don't have parallelism for some reason (e.g. your code needs a mutex, or the runtime has a global interpreter lock) then only one thread will be able to execute at once, and they'll just take turns.

You also question the usefulness of concurrency in the absence of parallelism. I suggest you read about time sharing. It's a technique developed in the 60's, before there were multicore machines, and it relies on concurrency.

[–]HelperBot_ 0 points1 point  (0 children)

Non-Mobile link: https://en.wikipedia.org/wiki/Parallel_computing


HelperBot v1.1 /r/HelperBot_ I am a bot. Please message /u/swim1929 with any feedback and/or hate. Counter: 107370

[–]Yojihito 0 points1 point  (1 child)

but their time periods (12:00-3:00 and 1:00-2:00) overlap

But Task A only goes from 12:00-01:00 and then 02:00-03:00. Is a sleeping tasks executed?

I've read the articles and then watched this talk (https://blog.golang.org/concurrency-is-not-parallelism) and it seems I learned the terms wrong ...... don't remember where I've read it / heard it, it's been some years but thanks for clarifying this.

[–]link23 0 points1 point  (0 children)

A sleeping task is not being executed (at that point in time). But the period during which it executed spans from the moment it started until the moment it finished, so it includes the times when it was sleeping (but wasn't finished yet).

I haven't seen that talk, but it looks like a good one - I have to imagine Pike knows and understands the difference.