Always_Beginner
Always_Beginner

Reputation: 2946

How does multithreading work on a singe-core system?

When multiple threads run on a single-core system , are those threads running simultaneously or sequentially with a fast context switch(which gives a feeling of threads running simultaneously)? Thanks

Upvotes: 2

Views: 75

Answers (2)

Andrew Lygin
Andrew Lygin

Reputation: 6197

Many modern processors adapt techniques that allow them to execute several threads on a single core. Such techniques are called Simultaneous multithreading (or SMT). For instance, "Hyper-threading" is the Intel's implementation of SMT.

SMT implies that a core can fetch and execute two or more instructions from different threads simultaneously, in one cycle. If the OS also knows how to work with SMT, it can schedule threads in a way that actually allows executing different threads on the same core simultaneously. In some cases it might give nearly the same boost as executing threads on two (or more in some processors) cores.

Otherwise, it's only context switching.

Upvotes: 3

clay
clay

Reputation: 20470

With a single CPU core, different threads don't literally run simultaneously, but the OS can prempt one thread and let another thread run.

Upvotes: 0

Related Questions