News for hackers. Stuff that matters.
Re:A Gentle Introduction to Multithreading by quietbritishjim on Tuesday March 12, 2019 @03:23AM (#19366061)
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.

Re:A Gentle Introduction to Multithreading by neurohacker on Tuesday March 12, 2019 @04:18AM (#19366258)
To build on what you're saying: while true from the user perspective, out-of-order execution and instruction level parallelism means there are some types of parallelism happening at the single core level. However, these systems are designed to produce results to the end user as though no micro-level parallelism is occurring.

I mention this mainly because I've recently discovered the joy of SIMD intrinsics. While it's pretty difficult to gain anything from out-of-order execution (cough other than a spectre) it's possible to take advantage of SIMD through compiler autovectorization, intrinsics, or assembly coding. SIMD doesn't have the problem of race conditions though as the parallel operations are non-conflicting and the user view of the computation is synchronous. I imagine under the hood there are all kinds of tricks at play for complex instructions that involve different microcircuits that take different numbers of cycles.

EDIT: clarified last sentence

Re:A Gentle Introduction to Multithreading by sliken on Tuesday March 12, 2019 @09:32PM (#19374900)
SMT (Like Intel's hyperthreading) can actually run 2 different instructions from 2 different processes in the same clock cycle on a single core.