开发者

Is this a correct Analogy for Process and Threads?

I am trying to get the hang of Process, Threads, MultiCore etc... So here's my analogy from what I have learnt..

A society is like a Computer.

A building is like a Chip.

A floor on a particular building is a Core on that Chip.

So a building can be one floor (single core on single chip),

One building multiple floors (multicore on a single chip),

Many building, many floors each(multiprocessor with multicore)

A flat in a particular floor is a Process.

A person living in a room in a particular flat is a thread.

People living in a particular flat, share the same space. i.e. each thread in a process share the same address space.

Each person shares few common 开发者_开发知识库things in the room like a kitchen, shower area etc i.e. each thread in a process share code, data, files

Shower room in a particular flat needs synchronisation between people (threads) living in that flat. As only one can use at a time.

Each person has its own personal set of things which he does not share with others, his underwear for example ;) (a thread has its own stack, registers)

A person can call new friends to his flat. i.e. A thread may spawn new threads for his her wishes (maybe the thread is bored lol)

The owner of the building, can shut down any room, create new rooms, or assign new tenants or chuck them out. Kernel can assign new process, and create destroy threads too.

......

Guys let me know if I got the analogy right. If anything else I can add to make it more clear or make it correct.

The only problem I see is when a process having many threads run on different cores... Any ideas how to include that in the analogy..?

Let me know. Thanks a lot. :)

Reference - https://www.his.se/PageFiles/4854/2010/threads_6slides.pdf?epslanguage=sv


In your example, Shower would be a limited resource possibly memory resource or device, which is why it must be shared. You didn't give the equivalent thing.

A thread doesn't have it's own registers, unless you mean something other than the registers in one of the cores of one of the CPUs. Threads share cores, so they are actually operating under time splices. I would compare it more to an apartment room has occupants move in and out, but then your shower idea falls apart. At which point I would say that it's the storage lockers that they must share, but only one tenant can use a particular locker at a time.

A process executes within the boundaries of a core, but it doesn't physically exist on the core, but I think for this case the metaphor is clear enough.

If you're worried about threads running on different cores, you can compare it to a prison shower room. Where guys(threads) move in and out of different showers(cores) even though they belong to different gangs(processes), and they have to share a set of lockers like before.

No matter what your analogy, it's hard to explain the time splices and rapid entering and exiting of different process/threads on a core.

And, the real problem I have with this, threads don't get bored :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜