go 单进程并发
demo1
// This sample program demonstrates how to create goroutines and
// how the scheduler behaves.
package main import (
"fmt"
"runtime"
"sync"
) // main is the entry point for all Go programs.
func main() {
// Allocate 1 logical processor for the scheduler to use.
runtime.GOMAXPROCS() // wg is used to wait for the program to finish.
// Add a count of two, one for each goroutine.
var wg sync.WaitGroup
wg.Add() fmt.Println("Start Goroutines") // Declare an anonymous function and create a goroutine.
go func() {
// Schedule the call to Done to tell main we are done.
defer wg.Done() // Display the alphabet three times
for count := ; count < ; count++ {
for char := 'a'; char < 'a'+; char++ {
fmt.Printf("%c ", char)
}
fmt.Println()
}
}() // Declare an anonymous function and create a goroutine.
go func() {
// Schedule the call to Done to tell main we are done.
defer wg.Done() // Display the alphabet three times
for count := ; count < ; count++ {
for char := 'A'; char < 'A'+; char++ {
fmt.Printf("%c ", char)
}
fmt.Println()
}
}() // Wait for the goroutines to finish.
fmt.Println("Waiting To Finish")
wg.Wait() fmt.Println("\nTerminating Program")
}
输出
Start Goroutines
Waiting To Finish
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
go 单进程并发的更多相关文章
- Linux服务器程序--大数据量高并发系统设计
在Linux服务器程序中,让系统能够提供以更少的资源提供更多的并发和响应效率决定了程序设计价值!怎样去实现这个目标,它其实是这么多年以来一直追逐的东西.最开始写代码时候,省去一个条件语句.用 ...
- UNIX网络编程——使用select函数编写客户端和服务器
首先看原先<UNIX网络编程--并发服务器(TCP)>的代码,服务器代码serv.c: #include<stdio.h> #include<sys/types.h> ...
- 使用select函数改进客户端/服务器端程序
一.当我们使用单进程单连接且使用readline修改后的客户端程序,去连接使用readline修改后的服务器端程序,会出现一个有趣的现象,先来看输出: 先运行服务器端,再运行客户端, simba@ub ...
- python 学习笔记 aiohttp
asyncio可以实现单进程并发IO操作,如果仅用在客户端,发挥的威力并不大,如果把asyncio用在服务器端,由于http链接就是IO操作, 因此可以用单线程+coroutine实现多客户的高并发支 ...
- redis数据库的使用
一.安装redis与可视化操作工具 可视化工具:RedisDesktopManager redis载地址:https://github.com/MSOpenTech/redis/releases. 二 ...
- django自带cache结合redis创建永久缓存
0916自我总结 django自带cache结合redis创建永久缓存 1.redis库 1.安装redis与可视化操作工具 1.安装redis https://www.runoob.com/redi ...
- redis的介绍与操作及Django中使用redis缓存
redis VS mysql的区别 """ redis: 内存数据库(读写快).非关系型(操作数据方便) mysql: 硬盘数据库(数据持久化).关系型(操作数据间关系) ...
- 在python当中使用redis
redis数据库 # 1.安装redis与可视化操作工具 # 2.在服务中管理redis服务器的开启关闭 # 3.命令行简单使用redis: -- redis-cli # 启动客户端 -- set k ...
- 认识和学习redis
redis VS mysql """ redis: 内存数据库(读写快).非关系型(操作数据方便) mysql: 硬盘数据库(数据持久化).关系型(操作数据间关系) 大量 ...
随机推荐
- ASP.NET定时调用WebService 运行后台代码
效果: 通过在网站的Global.asax的Application_Start方法中 加入定时器 定时调用WebService 该WebService的一个方法 负责在后台 向数据库的某个表加入数据 ...
- Censor SCU - 4438
frog is now a editor to censor so-called sensitive words (敏感词). She has a long text (p). Her job is ...
- 基于rsync的lsyncd自动同步配置
环境部署 源机:192.168.31.140 目标机:192.168.31.130 源机配置 基于rsync的lsyncd 自动同步,rsync的配置省略 安装lsyncd rpm -ivh lsyn ...
- H5+JS生成验证码
效果图如下: <canvas id="canvas1" style="margin-left: 200px;"></canvas>< ...
- Golang面向对象_继承
package main import "fmt" type Person struct { name string //名字 sex byte //性别 age int //年龄 ...
- fjwc2019 D3T2 送分题
#185. 「2019冬令营提高组」送分题 这是原题..... P3615 如厕计划 手推一推你发现,显然男性不能多于女性. 然后你或许可以发现一个神奇的性质. 对于每个序列,我们记$M$为$1$,$ ...
- AMQP 0.9.1和1.0协议差别以及rabbitmq支持情况
RabbitMQ implements AMQP 1.0 via a plugin. However, AMQP 1.0 is a completely different protocol than ...
- [VS] - "包含了重复的“Content”项。.NET SDK 默认情况下包括你项目中的“Content”项。
copy to :http://www.cnblogs.com/jinzesudawei/p/7376916.html VS 2017 升级至 VS 2017 v15.3 后,.Net Core 1 ...
- (2编写网络)自己动手,编写神经网络程序,解决Mnist问题,并网络化部署
基于<神经网络和深度学习>这本绝好的教材提供的相关资料和代码,我们自己动手编写"随机取样的梯度下降神经网络".为了更好地说明问题,我们先从简单的开始: 1.sigmod ...
- py4CV例子3Mnist识别和ANN
1.什么是mnist数据集: , , ], ,,,,,,,,]], ., ., , , ], ,,,,,,,,]], ., ., , , ])) animals_net.setTermCriteri ...