Go-语言特性

天然并发

  • 从语言层面支持并发,
  • goroute,轻量级线程
  • 基于CSP模拟实现

channel

  • 管道,类似于linux的pipe
  • 多个goroute之间通过channel进行通信
  • 支持任何类型
管道
func test_pipr()  {
    //管道放入数据
    pipe := make(chan int,3)
    pipe <- 1
    pipe <- 2
    pipe <- 3
    //先进先出
    //pipe <- 4
    //fatal error: all goroutines are asleep - deadlock!
    fmt.Println(len(pipe))

    var t int
    t =<- pipe
    fmt.Println(t)
    fmt.Println(len(pipe))
}

文件整理 gofmt -w file.go

go的多线程,可以使用管道来引出数据

多值返回

    var c int = a + b
    var d int = a + a + b
    return c,d
}

func main()  {
    a,b := many_return(100,200)
    fmt.Println("a=",a,"b=",b)
}

常量

  1. const 只能修饰boolean,number,(int相关类型、浮点类型、complex)和string
  2. const identifier [type] = value 其中type可以省略

    eg:

const b string = "hello world"
const b = "hello world"
const Pi = 3.1415926
const a = 9/3

值类型和引用类型

  1. 值类型:基本数据类型int、float、bool、string以及数组和struct
  2. 引用类型:指针、slice、map、chan等
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值