计算机面试 1.0 Help

1.1 管道

/** * @Author : gainovel * @Organization : Copyright © 2024 gainovel.com All Rights Reserved. * @Date : 2024-03-19 18:18:14 星期二 * @ProductName : Writerside * @PrjectName : interview * @File : Writerside/topics/1.1-管道.md * @Version : v0.1.0 * @Description : ... **/

第一部分

选中Section Once时应该显示的内容。

Section Two

The content that should appear when the Section Two is selected.

系列文章

chan简介

管道时Go在语言层面提供的协程间的通信方式,比UNIX管道更易用也更轻便

chan特征

FIFO,先入先出。

协程读取管道时,阻塞的条件有3个:

  1. 管道无缓冲区

  2. 管道缓冲区中无数据

  3. 管道为nil。

协程写入管道时,阻塞的条件有3个:

  1. 管道无缓冲区

  2. 管道缓冲区已满

  3. 管道为nil。

panic的情况有两种,①向关闭的管道写数据会触发panic②关闭已经关闭的管道。

  1. First item.

    1. First indented item.

    2. Second indented item.

  2. Second item.

  3. Third item

  4. Fourth item

  • Some list item

  • Another list item

  • Yet another list item

    • Some indented item

    • Another indented item

  • One more item

class Person(val name: String) { val children: MutableList = mutableListOf() constructor(name: String, parent: Person) : this(name) { parent.children.add(this) } }
class Person(val name: String) { val children: MutableList = mutableListOf() constructor(name: String, parent: Person) : this(name) { parent.children.add(this) } }
class Person(val name: String) { val children: MutableList<Person> = mutableListOf() constructor(name: String, parent: Person) : this(name) { parent.children.add(this) } }

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

①向关闭的管道写数据会触发panic


②关闭已经关闭的管道


Add something

Before adding something, create it.

  1. Do this.

  2. Do that.

Congratulation! You've added something.

Link to anchor

管道关闭后,仍然可以读取数据。

使用逗号模式(val,ok := <-ch1)从管道中读取数据,ok为bool类型,表示是否读取到数据。

管道关闭&管道缓冲区中无数据 ⇌ ok为false;管道关闭后读取管道需通过ok判断本次是否读取到数据,以防返回零值,误操作。

如何判断管道是否关闭?

class Person(val name: String) { val children: MutableList<Person> = mutableListOf() constructor(name: String, parent: Person) : this(name) { parent.children.add(this) } }

Do a barrel roll

Whenever you are not sure what to do, try a barrel roll first, then ask for help.

Whenever you are not sure what to do, try a barrel roll first, then ask for help.

dsfsafa ...

AliceJohnHello John, how are you?Great!See you later!AliceJohn
Last modified: 21 三月 2024