Skip to content

Process vs Thread

Task: Run the same work twice, once as processes and once as threads

TWO PROCESSESONE PROCESS, TWO THREADScode + globalsheapcount = 1stackthreadProcess Acode + globalsheapcount = 0stackthreadProcess Bcode + globalsheapcount = 1stackthread 1stackthread 2One processboth threads read the same heap

What you are watching

The difference between a process and a thread, shown as memory. A process is a box holding code, globals, a heap and a stack, run by at least one thread. Starting a program twice gives two boxes that cannot see each other, so a value written in one is invisible in the other. Two threads in one process instead share the code, the globals and the heap, and keep only a stack each, so a value one writes the other reads immediately.