[fpc-pascal] Threading vs Parallelism ?

Karoly Balogh (Charlie/SGR) charlie at scenergy.dfmk.hu
Thu Mar 30 00:10:36 CEST 2017


Hi,

On Wed, 29 Mar 2017, fredvs wrote:

> > besides hardware parallelism,
>
> Is it possible, with fpc, to assign one processor (if multi) for a
> thread and say to the system to use this one only for the thread ? But
> maybe it will gives more problems than solutions.

Yes, it's called thread/process affinity, and most operating systems have
a specific API for it. But one should treat such things extremely
carefully, otherwise with badly designed data access concurrency you end
up with potentially hard to identify structural problems like false
sharing (see Wikipedia on this) and others. This can be especially bad for
for example on NUMA architectures, or others, where data storage locality
to a given core is not obvious. (Just think about clusters, etc.)

In other words, as the OS knows best your hardware's layout and how it can
best provide performance, energy, bandwith, etc, it's usually very wise to
rely on the OS to solve the thread to CPU core assignments for you.

Bottom line: parallelism and threading is a very complex problem and very
diverse area, and anyone laughing at any approach is just shows how little
they know about true depth of the whole topic, IMO. Thinking about any
technical solution, or way of implementation as a silver bullet for
everything is a very "expert beginner" approach.

My 2 cents.

Charlie



More information about the fpc-pascal mailing list