Live data from Hacker News

A Gentle Introduction to Multithreading

internalpointers.com

11–15 of 15 posts

Re: A Gentle Introduction to Multithreading

#11
post #4

> it is not 100% guaranteed that threads will perform their operations truly in parallel, that is at the same time: it really depends on the underlying hardware. I thought it really depended on a lot of factors, most predominantly thread scheduling (based on thread priority)[0]? [0] - https://docs.microsoft.com/en-us/windows/desktop/ProcThread/...

Are there any operating systems that let you explicitly run CPUs in parallel? I'm thinking n threads where the process requests the operating system scheduler to start and stop them all at the same time. Of course the OS would be permitted to refuse if it wasn't capable (or just not allowed). A synchronised cpu master-slave relationship could be beneficial to parallelize some of the middle ground between instruction…

Why would you want to override the scheduler like that? That would also mean not scheduling your process until all the CPUs were clear, and greatly increasing scheduler coordination overhead. So it would decrease overall work throughput.

CPU affinity is genuinely useful, but I can't see why you'd want this kind of temporal affinity. Especially since you could have different CPUs running at different speeds!

Re: A Gentle Introduction to Multithreading

#14
post #4

> it is not 100% guaranteed that threads will perform their operations truly in parallel, that is at the same time: it really depends on the underlying hardware. I thought it really depended on a lot of factors, most predominantly thread scheduling (based on thread priority)[0]? [0] - https://docs.microsoft.com/en-us/windows/desktop/ProcThread/...

Are there any operating systems that let you explicitly run CPUs in parallel? I'm thinking n threads where the process requests the operating system scheduler to start and stop them all at the same time. Of course the OS would be permitted to refuse if it wasn't capable (or just not allowed). A synchronised cpu master-slave relationship could be beneficial to parallelize some of the middle ground between instruction…

You can get that effect by pinning processors to threads and you can do the sync yourself with a barrier (like Java CyclicBarrier, not a memory barrier.)

Re: A Gentle Introduction to Multithreading

#15

> it is not 100% guaranteed that threads will perform their operations truly in parallel, that is at the same time: it really depends on the underlying hardware. I thought it really depended on a lot of factors, most predominantly thread scheduling (based on thread priority)[0]? [0] - https://docs.microsoft.com/en-us/windows/desktop/ProcThread/...

It depends on a lot of factors, but if your CPU physically does not have multiple cores then you can be 100% sure that your threads will not be executing code literally in parallel. I think on most operating systems, if you have a multicore CPU and very little load apart from your program, and you run CPU-bound code in multiple threads, then you will see those threads executing in parallel in different cores.

SMT (Like Intel's hyperthreading) can actually run 2 different instructions from 2 different processes in the same clock cycle on a single core.
Post reply on HN