Multithreading Is NOT What You Think

preview_player
Показать описание
Follow for more Android & Kotlin tips 🙌
Рекомендации по теме
Комментарии
Автор

If you only have 1 core CPU, yes. this is called interleaving. But, if you have more than one core CPU it really run in parallel mode. This is called concurrency and naturally create race conditions.

That's why you will also need mutex or signaling to make the program run in atomic.

ahmadamirudin
Автор

I think this video is misleading. You do say at the end, that "multithreading != parallelism" is only true if you have a single-core CPU, but any computer from the last 10 years has at least 2 cores, so parallelism is not just an illusion and in fact what is powering the continuing increase of CPU performance within the last few years.
Nevertheless, it is of course important to make sure that your threads are actually executed on different CPU cores if you are going for the performance increase.

robinwersich
Автор

i think what you mean here is asynchronous task, not multi-threading, multi-threading means you're running different task on different thread (cpu)

ban_droid
Автор

The burger analogy might be causing confusion in the comments. When people hear about a patty cooking on the grill while prepping other ingredients, it sounds like two tasks happening simultaneously, leading them to think of parallelism. A clearer distinction might be: Parallelism is like multiple chefs working on separate tasks to make a burger at once. Multithreading is one chef quickly switching between tasks, realizing he needs to wait for his shipment of meat still to come in 3 minutes (but does not stop working because there's another thread to work on), so he moves on to another thread like cutting the buns in the meantime.

chair_smesh
Автор

Misleading. They can run in parallel if there is more than one CPU core

Nomnomnom
Автор

If u watch this video with less attention only Once. It seems misleading.
Because Only towards the end he mentions that as long as Cpu has only 1 core Multithreading is not parallel.

elgobert
Автор

Misleading video. Whether threads run in parallel or only concurrent depends on the cores that you have, language, and also how the OS distribute them. Most languages have abstracted away so that we don't need to think if it's run in parallel or only cuncorrent, but when you dispatch a thread you know for sure it'll run in concurrent. Also remember that paralleism ALSO INCLUDES CONCURRENCY.

ihsannuruliman
Автор

This would be true 10+ years back; but now it’s different. Logical processors (CPU threads) are how much it can run in parallel. (Old processors had one logical processor per cpu)

each logical processor can have multiple threads assigned and work as you said in the video;

e.g. 10 threads to one logical processor will make it process them by switching between them fast

But if there was 16 logical processors and 16 threads, all 16 threads will be running simultaneously.

To make it even simpler for those who don’t understand it; imagine mini cpus within one big cpu. Each mini cpu is a logical processor, and read this comment again for the rest of the explanation.

millopodia
Автор

I think your example explains concurrency. So you can say (like Rob Pike) concurrency is not parallelism.

The term multithreading is ambiguous, and it could be parallelism as well as non-parallelism depending on the cpu.

Check Wikipedia

martinmaartensson
Автор

For the people who still think it is parallel. I recently discovered this trying to make my algorithm (in C#) run faster. It literally ran slower every time I tried something with multithreading.

Thinking I did something wrong, I made the most simple multithreading test on a basic array. It was ALWAYS slower than running on a single thread.

So I basically had this exact wrong assumption for 15+ years, feeling like a total noob. Multithreading was never meant for any raw performance increase. It is meant to avoid waiting for some task to finish before you can do something else, but the total instructions execution time is always at least the same.

letmehhealplx
Автор

My lecturer one said “multithreading is just an optimized scheduling” 🤣

mzfkr
Автор

As most already highlighted, this isn't true if you have multiple cores. But I also wanted to add that this is not true even for some single core CPU that are capable of combining instructions... So it depends on many many factors, and trust me hardware - is actually the least important of them...

VilRapt
Автор

multi-threading is about concurrency, and parallelism isn't necessarily guaranteed, but it practically is because most modern CPUs utilize several threads and cores

wertia
Автор

I understand...
That multiprocessing is using parallelism in its tasks now.

I was wondering how threads are executed on the "same memory pool" while processes use different memories altogether...

Cuz thread' is just quick switchin'.
👌

manitro
Автор

I feel like this video is mixing up async and multithreading.

I also feel like it's ignoring the abstractions involved with operating systems and kernels.

Just because things aren't literally happening on the physical hardware they can still be virtually affected.

Multithreading can have a race condition while async not so much.

GmanGavin
Автор

What about the new Simultaneous and Heterogenous Multithreading?

TheLinuxManual
Автор

Confusing explanation. Multithreading is just running code in multiple threads. And what you are saying about them not being run in parallel was true 20 years ago but now processors have several cores and physically can execute different lines of code at the same time.

alexanderj
Автор

As they say, do not confuse with each other: Parallel, asynchronous and suspended computing.

aliaksandrbohush
Автор

They aren't synonymous but they have correlation

TheDeeStain
Автор

Parallelism implies concurrency and reverse is not true.

if CPU has one core, u can run multiple threads and achieve concurrency but not parallelism.

raviteja
visit shbcf.ru