>
Concurrency generally means preemptionNo, it doesn't. Concurrency is about the logical structure of the code. From Wikipedia:
"In computer science, concurrency is the decomposability
property of a program, algorithm, or problem into order-
independent or partially-ordered components or units. This
means that even if the concurrent units of the program,
algorithm, or problem are executed out-of-order or in
partial order, the final outcome will remain the same".
And from "Parallel and Concurrent Programming in Haskell":
In many fields, the words parallel and concurrent are
synonyms; not so in programming, where they are used to
describe fundamentally different concepts.
A parallel program is one that uses a multiplicity of
computational hardware (e.g. multiple processor cores) in
order to perform computation more quickly. Different parts
of the computation are delegated to different processors
that execute at the same time (in parallel), so that
results may be delivered earlier than if the computation
had been performed sequentially.
In contrast, concurrency is a program-structuring technique
in which there are multiple threads of control. Notionally
the threads of control execute "at the same time"; that is,
the user sees their effects interleaved. Whether they
actually execute at the same time or not is an
implementation detail; a concurrent program can execute on
a single processor through interleaved execution, or on
multiple physical processors.
Note: "program-structuring technique", "Notionally" and "implementation detail".
Concurrency is NOT "running in parallel" (running simultaneously), as you seem to believe, and not even about your code getting preempted. As long as it's structured concurrently, that is.
But if you have concurrency AND preemption OR different independent processes etc over multiple cpus you can have parallelism. In a sense concurrency is a more generic principle.