Created
April 4, 2016 03:34
-
-
Save xiaq/fccdb5ae8807281b595e7c9fd64dd70e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "os" | |
| ) | |
| func e(err error) { | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| } | |
| func main() { | |
| f, err := os.OpenFile("./a", os.O_RDWR|os.O_CREATE, 0644) | |
| e(err) | |
| ch := make(chan bool) | |
| go func() { | |
| _, err := f.WriteString("233") | |
| e(err) | |
| ch <- true | |
| }() | |
| go func() { | |
| var buf [3]byte | |
| n, err := f.Read(buf[:]) | |
| e(err) | |
| fmt.Println(string(buf[:n])) | |
| ch <- true | |
| }() | |
| <-ch | |
| <-ch | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment