seegongsik
Saved words
Operating systems

Many strands in one task

Split one job into several strands moving at once in one shared room.

01

One person, many hands

One cook works in a kitchen. They simmer the soup, chop vegetables at the same time, and check the flame now and then.
The job is one thing, cooking, but inside it several strands are handled together. One kitchen, one shelf of ingredients, shared.
A computer can split one task into several strands like this too. Each of those strands is called a thread.

Task (cooking)CookSimmer soupChop vegWatch flameShelf (shared)

One job, many strands inside it. The kitchen and ingredients are shared

A thread is one of several strands moving along at the same time inside one task.

02

Two separate houses, many rooms in one house

Earlier we said each process has its own separate space. Two processes are like neighboring houses. There is a wall, so they cannot just walk into each other.
But the threads inside one process are like family living in one house. The rooms may be separate, but the living room and fridge are shared.
So threads pass information to each other easily. They are looking at the same shelf. Between processes that is more of a hassle.

Processes: a wallThreads: sharedstrangerssharedone familyliving room and fridge shared

Processes are neighbors with a wall, threads are family in one house

Processes use separate spaces, while threads inside one process share the space.

03

Add more strands

Change how many strands one task is split into.
With one strand, the work is done one step after another. Add strands and several parts move at the same time. All looking at the same shelf.
More strands can finish the work faster. But since everyone uses the same kitchen, too many can start blocking each other. Add some and watch how the work splits.

Shelf (shared)
Strand 1
Strand 2
Strands2
Add strands and several parts move at once. But there is one shelf, so they share it.

Change the number of strands and watch how one task splits and moves

More strands move more at once, but sharing the same space stays the same.

04

Sharing is fast, but

Threads sharing the shelf is a big plus. Without moving or copying things separately, they see the same thing right away, so it is light and fast.
But there are two sides. If two strands try to touch the same ingredient at the same moment, they can collide. One adds salt while the other adds it too.
So sharing is convenient, but it needs a little care about when and who touches what. We will say more about this next time.

UpsideShelfSeeing the same is light and fasttwo sidesCareTouching at once collides

Sharing is light and fast, but touching the same thing at once collides

Sharing the space is fast and light, but touching the same thing at the same time can cause trouble.

05

Put it on one page

Just remember three things.
First, threads are several strands inside one task. The job is one, but several parts move inside it at the same time.
Second, they share the same space. Processes have a wall between them, but threads inside one process look at the same shelf. Third, that makes it light and fast but also needs care. Touching the same thing at the same time can collide.

One
Threads are several strands inside one task. The job is one, but several parts move at once.
Two
They share the same space. Processes have a wall, threads look at the same shelf.
Three
Light and fast but needs care. Touching the same thing at once can collide.

Many strands in one task, shared space, light but careful

In one lineThreads split one task into several strands moving together in the same space.
Was this helpful? Support seegongsik
Operating systems