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: 硬盘数据库(数据持久化).关系型(操作数据间关系) 大量 ...
随机推荐
- how to backup your system of Autel MS908 Pro
how to backup your system of Autel Scan Tool Autel MS908 Pro: Connect the tablet to a PC desktop or ...
- django框架基本介绍
一.mvc和mtv 1.mvc介绍 MVC,全名是Model View Controller,是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器( ...
- 如何获取STM32 MCU的唯一ID及应用(转)
源: 如何获取STM32 MCU的唯一ID
- Jquery autocomplete.js输入框联想补全功能
Jquery autocomplete.js插件下载地址:http://files.cnblogs.com/files/jinzhiming/autocomplete.rar 有两种用法,一种是直接使 ...
- python类的__slots__属性、__del__属性、上下文(__enter__和__exit__)、
常规情况下,类的属性字典是共享的,而实例的字典是独立的.如果一个类的属性较少,但是拥有很多的实例,这些实例的属性字典会占用较多的内存空间.对这样的类来说,为了节省内存空间,可以使用__slots__类 ...
- 爬虫的基本操作 requests / BeautifulSoup 的使用
爬虫的基本操作 爬虫基础知识 什么是爬虫? 在最开始,还没有诞生Google和百度等一系列搜索引擎的公司的时候,人们进入一些公司的网站只能通过在浏览器地址栏输入网址的方式访问,如同在很早之前前手机不流 ...
- keepalived的原理以及配置使用详解
一.vrrp协议简介 VRRP(Virtual Router Redundancy Protocol)协议是用于实现路由器冗余的协议. VRRP协议将两台或多台路由器设备虚拟成一个设备,对外提供虚拟路 ...
- libvirt的security
1. libvirt支持SASL authentication and encryption MD5 hashes are considered unsafe and should not be us ...
- 本地win7ping VM linux ipv6地址问题
前述 在windows和linux同时安装ipv6之后,系统将会自动分配一个link-local(链接本地)地址也就是ifconfig -a看到的一行[inet6 addr: fe80::20c:29 ...
- mint-ui之tabbar使用
<template> <div> <!-- tabcontainer --> <mt-tab-container class="page-tabba ...