惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyberwarzone
Cyberwarzone
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Exploit Database - CXSecurity.com
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
GbyAI
GbyAI
A
Arctic Wolf
Simon Willison's Weblog
Simon Willison's Weblog
美团技术团队
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
NISL@THU
NISL@THU
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
N
News and Events Feed by Topic
M
MIT News - Artificial intelligence
T
Tenable Blog
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
S
Security Affairs
T
Troy Hunt's Blog
月光博客
月光博客
SecWiki News
SecWiki News
PCI Perspectives
PCI Perspectives
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
IT之家
IT之家
F
Full Disclosure
博客园_首页
C
CERT Recently Published Vulnerability Notes
T
Threatpost
Last Week in AI
Last Week in AI
C
Cisco Blogs
H
Heimdal Security Blog
大猫的无限游戏
大猫的无限游戏
Webroot Blog
Webroot Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Attack and Defense Labs
Attack and Defense Labs
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
量子位
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
I
InfoQ
P
Proofpoint News Feed
Y
Y Combinator Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main

博客园 - 远洪

大模型常用术语 windows 使用sshAgent 加载秘钥 再次认识java反射 再次认识java注解 再次认识java泛型 java中类的分类 java类中的成员变量,静态变量与局部变量 再谈java枚举enum 使用CCProxy让手机访问电脑能访问的网址 playwright启动后报错net::ERR_CERT_COMMON_NAME_INVALID 解决方法 debian 或ubuntu安装使用tigervnc python 实例属性、类属性、实例方法、类方法、静态方法 python面向对象封装,私有变量 docker compose使用 docker 自定义网络 Dockerfile 使用 go语言多态中的类型断言 java中的多态与golang中的多态 golang 定义接口
golang进程(主线程)与协程
远洪 · 2024-01-12 · via 博客园 - 远洪

概念

主线程:golang 中的主线程(在go中主线程就是进程,相比与其他编程语言叫法不一样)

协程:golang中协程是轻量级的线程(相比于其他语言,只有进程和线程);python中有进程和线程的概念,也有协程的概念;python中的协程通过async 来实现

并发与并行的概念

并发:在一个cpu上有10个线程,每个线程10毫秒(进行轮番操作),从人的角度看,好像这10个线程都在运行,单重微观来看,在某一个时间点只有一个线程在执行,这就是并发。

并行:在多个cpu上(例如10个cpu)有10个线程在执行,每个线程执行10毫秒(各自在不同的cpu上执行),从人的角度上来看,这10个线程都在执行,从微观角度来看,这10个显示也是都在执行,这就是并行。

go语言协程简单实现

package main

import (
    "fmt"
    "strconv"
    "time"
)

func GoPrintTest(){
    for i := 0;i < 3;i++ {
        fmt.Println("协程执行:" + strconv.Itoa(i))
        time.Sleep(1 * time.Second)
    }
}

func main(){
    // 通过 go 关键字启动一个协程
    go GoPrintTest()

    for i := 0;i < 3;i++ {
        fmt.Println("主线程执行:" + strconv.Itoa(i))
        time.Sleep(1 * time.Second)
    }
}