- Distributed Computing with Go
- V.N. Nikhil Anurag
- 270字
- 2021-06-24 18:36:10
Concurrency
Let's look at the concept of concurrency using a simple example of a few daily routine tasks and the way we can perform them.
Imagine you start your day and need to get six things done:
- Make hotel reservation
- Book flight tickets
- Order a dress
- Pay credit card bills
- Write an email
- Listen to an audiobook
The order in which they are completed doesn't matter, and for some of the tasks, such as writing an email or listening to an audiobook, you need not complete them in a single sitting. Here is one possible way to complete the tasks:
- Order a dress.
- Write one-third of the email.
- Make hotel reservation.
- Listen to 10 minutes of audiobook.
- Pay credit card bills.
- Write another one-third of the email.
- Book flight tickets.
- Listen to another 20 minutes of audiobook.
- Complete writing the email.
- Continue listening to audiobook until you fall asleep.
In programming terms, we have executed the above tasks concurrently. We had a complete day and we chose particular tasks from our list of tasks and started to work on them. For certain tasks, we even decided to break them up into pieces and work on the pieces between other tasks.
We will eventually write a program which does all of the preceding steps concurrently, but let's take it one step at a time. Let's start by building a program that executes the tasks sequentially, and then modify it progressively until it is purely concurrent code and uses goroutines. The progression of the program will be in three steps:
- Serial task execution.
- Serial task execution with goroutines.
- Concurrent task execution.
- Getting Started with oVirt 3.3
- 發(fā)布!設(shè)計與部署穩(wěn)定的分布式系統(tǒng)(第2版)
- Linux內(nèi)核完全注釋(20周年版·第2版)
- 無蘋果不生活 OS X Mountain Lion隨身寶典
- 白話區(qū)塊鏈
- Extending Bootstrap
- Installing and Configuring Windows 10:70-698 Exam Guide
- 異質(zhì)結(jié)原理與器件
- 巧學(xué)活用Windows 7
- VMware NSX Cookbook
- Dreamweaver CS5.5 Mobile and Web Development with HTML5,CSS3,and jQuery
- INSTANT Migration from Windows Server 2008 and 2008 R2 to 2012 How-to
- Linux服務(wù)器配置與管理
- bash shell腳本編程經(jīng)典實例(第2版)
- Docker容器技術(shù)與應(yīng)用