首页 > 其他分享 >Goroutines example

Goroutines example

时间:2023-05-03 11:33:52浏览次数:33  
标签:fmt go func time Println example Goroutines

一个入门的goroutines例子

package main

import (
    "fmt"
    "time"
)

func f(from string) {
    for i := 0; i < 3; i++ {
        fmt.Println(from, ":", i)
    }
}

func main() {

    f("direct")

    go f("goroutine")

    go func(msg string) {
        fmt.Println(msg)
    }("going")

    time.Sleep(time.Second)
    fmt.Println("done")
}

标签:fmt,go,func,time,Println,example,Goroutines
From: https://www.cnblogs.com/bovyfly/p/17368857.html

相关文章

  • Tool-CMake-A Simple CMake Example
    Tool-CMake-ASimpleCMakeExamplehttps://cmake.org/examples/Therearethreedirectoriesinvolved.Thetopleveldirectoryhastwosubdirectoriescalled./Demoand./Hello.Inthedirectory./Hello,alibraryisbuilt.Inthedirectory./Demo,anexecuta......
  • 10 iozone Examples for Disk I/O Performance Measurement on Linux
    https://www.thegeekstuff.com/2011/05/iozone-examples/ Aswediscussedinour Linuxperformancemonitoringintroduction article,measuringIOsubsystemperformanceisveryimportant.Ifsomeoneiscomplainingthatadatabase(oranyapplication)running......
  • 论文解读(FGSM)《Explaining and Harnessing Adversarial Examples》
    论文信息论文标题:ExplainingandHarnessingAdversarialExamples论文作者:IanJ.Goodfellow,JonathonShlens,ChristianSzegedy论文来源:ICLR2015论文地址:download 论文代码:download视屏讲解:click1 介绍对抗攻击2方法扰动:$\eta=\varepsilon\operat......
  • cmake string example
    string(CONCATresult${var1}"/how")string(FIND${var1}"targetPattern"foundResultIndex)if(${foundResultIndex}GREATER_EQUAL0)endif()string(LENGTH<string><output_variable>)https://cmake.org/cmake/help/lates......
  • ECMAScript Regular Expressions Tutorial with Examples
    ORi:https://o7planning.org/12219/ecmascript-regular-expression-RegularExpression  Aregularexpressiondefinesasearchpatternforstrings.Regulare......
  • 安装example
     在https://github.com/tensorflow/tensorflow/tree/master/tensorflow中下载出两个压缩包如下:  把下载好的压缩包解压把里面的tensorflow下的examples文件夹直......
  • vscode & ESP-IDF 之 Example 尝试
    买了几个ESP32-S3和ESP32-C3,还有ILI3941和ILI94883.5寸屏,想上LVGL,但是网上的例程大部分都是ESP-IDF编译的。而我才对micropython入门,没办法,在bilibili上下了几个视频......
  • Gradient-based Editing of Memory Examples for Online Task-free Continual Learnin
    摘要:在缺少明确的任务边界和任务标识的情况下,本文探索了task-freecontinuallearning(任务具有独立的数据标签空间,在训练和测试的过程中不提供任务识别符),在这个场景中需......
  • element-ui的el-form表单和el-table校验_Example
    <template><div><el-dialog:title="'新建'":close-on-click-modal="false"append-to-body:visible.sync="visible"><el-form:model="dataF......
  • 用GoRoutines高性能同时进行多个Api调用
    用GoRoutines高性能同时进行多个Api调用转载请注明来源:https://janrs.com/2023/03/用goroutines同时进行多个api调用/Golang是高效的,非常高效。这种效率在很大程度上要......