Misunderstanding the difference between single-threading and multi-threading programming

前端 未结 6 1456
梦毁少年i
梦毁少年i 2021-01-31 16:12

I have a misunderstanding of the difference between single-threading and multi-threading programming, so I want an answer to the following question to make everything clear.

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-31 16:30

    Assumption Set: Single core with no hyperthreading; tasks are CPU bound; Each task take 3 quanta of time; Each scheduler allocation is limited to 1 quanta of time; FIFO scheduler Nonpreemptive; All threads hit the scheduler at the same time; All context switches require the same amount of time;

    Processes are delineated as follows:

    • Test 1: Single Process, single thread (contains all 9 tasks)
    • Test 2: Single Process, three threads (contain 3 tasks each)
    • Test 3: Three Processes, each single threaded (contain 3 tasks each)
    • Test 4: Three Processes, each with three threads (contain one task each)

    With the above assumptions, they all finish at the same time. This is because there is an identicle amount of time scheduled for the CPU, context switches are identicle, there is no interrupt handling, and nothing is waiting for IO.

    For more depth into the nature of this, please find this book.

提交回复
热议问题