[clug] threads v processes
arjen at lentz.com.au
Thu Sep 6 18:17:25 MDT 2012
> Has anyone out there in CLUG-land used POSIX thread libraries and
> willing to help me understand a small design point about them?
> I was reading a paper by Rob Pike and he mentions:
Article from when?
> - Processes need to lock shared memory because they *can* execute in
> parallel (simultaneously)
Regardless of the underlying CPU/core layout, that's a half-truth.
Depending on the layout, measures must be taken to prevent simultaneous access. However, that might not be locking as such. There are lock-free algorithms, and obviously tricks like that greatly improve concurrency. Not practical in all uses, but definitely an option.
> - threads within a single process don't ever execute simultaneously.
This is fundamentally untrue, at least in modern kernels.
MySQL is single-process, multi-threaded (always has been) and it's very happy to spread across cores and CPUs - executing simultaneously. Typically a thread would handle a single client connection, but more recent MySQL versions can also pool threads and thus have fewer threads with more connections. Anyhow, the point is that threads in a single process most definitely execute in parallel, on multiple cores as well as on multiple CPUs.
> Does anyone know if this is right with Linux on multi-core
With info from the real world: no. incorrect (for modern kernels at least).
Someone else with more kernel background can surely give more detail.
Exec.Director @ Open Query (http://openquery.com) MySQL services
Sane business strategy explorations at http://upstarta.com.au
Personal blog at http://lentz.com.au/blog/
More information about the linux