From 8632abfd39e4727ca7a03807bfe8f840708c7827 Mon Sep 17 00:00:00 2001 From: Dinh Phu Nguyen Date: Fri, 2 Aug 2024 11:46:46 +0700 Subject: [PATCH] Add Post concurrency-programming --- _drafts/2024-08-02-concurrency-programming.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 _drafts/2024-08-02-concurrency-programming.md diff --git a/_drafts/2024-08-02-concurrency-programming.md b/_drafts/2024-08-02-concurrency-programming.md new file mode 100644 index 0000000..16ca19d --- /dev/null +++ b/_drafts/2024-08-02-concurrency-programming.md @@ -0,0 +1,28 @@ +--- +layout: post +title: Concurrency Programming +date: 2024-08-02 08:30:00-0400 +description: Concurrency allows programs to deal with many tasks at once. +tags: performance +categories: system-design +giscus_comments: true +related_posts: false +toc: + beginning: true +--- + +### Introduction + +Concurrency allows programs to deal with many tasks at once. But writing concurrent programs is not really easy. We will face with so many problem such as: threads, race conditions, deadlocks,... + +### History of computer + +So many years ago, the hardware power of computer is not powerful as today. CPU and RAM are limited, a task it can process in a while depends on CPU Clock Speed. In that days, to increase the tasks which computers can process in the same time, they enhance the core, clock speed of CPU. But dealing with threads manually is not a easy feat for developers, and they can't increase the CPU Clock Speed and number of core to much because of technical circumstances. + +When CPU and RAM become more powerful, to solve this problem, we don't handle threads directly but append tasks to a queue. Everything about threads should be managed by system. Developer only needs to manage how the tasks should be process. + +### What is concurrency? + +In abstraction, we can think that many tasks can be processed in the same time. In detail, tasks are not really processed at the same time, they're suspended when they don't need CPU (waiting for IO) and allow next task in queue processed. When the task that suspended completes IO, it will be continued. + +In this way, we don't need multi threads to write a concurrent program. The task can be processed in sequential queue in only 1 thread system, or concurrent queue in multi thread system to optimize CPU resource.