Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cb5ba2f

Browse files
committed
add closures
1 parent 1fdd637 commit cb5ba2f

File tree

5 files changed

+96
-3
lines changed

5 files changed

+96
-3
lines changed

‎README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636

3737
|Id | Topic | Docs
3838
|---|----------------------------------------------------------------------------------------|--------------------------------------------------|
39-
| 00| [Data structure](https://github.com/utilityCode-Foundation/go-playground/tree/master/data-structure) | [User Guide]() |
40-
| 01| [Algorithm](https://github.com/utilityCode-Foundation/go-playground/tree/master/algorithm) | [User Guide]() |
41-
| 02| [Design pattern](https://github.com/utilityCode-Foundation/go-playground/tree/master/design-pattern) | [User Guide]() |
39+
| 00| [Closures](https://github.com/utilityCode-Foundation/go-playground/tree/master/closures) | [User Guide]() |
40+
| 00| [Concurrency](https://github.com/utilityCode-Foundation/go-playground/tree/master/concurrency) | [User Guide]() |
41+
| 01| [Data structure](https://github.com/utilityCode-Foundation/go-playground/tree/master/data-structure) | [User Guide]() |
42+
| 02| [Algorithm](https://github.com/utilityCode-Foundation/go-playground/tree/master/algorithm) | [User Guide]() |
43+
| 03| [Design pattern](https://github.com/utilityCode-Foundation/go-playground/tree/master/design-pattern) | [User Guide]() |
4244

4345
# Table of Content (Work with data storages)
4446

‎closures/README.md

Whitespace-only changes.

‎concurrency/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Parallelism vs Concurrency
2+
3+
Parallelism means running two operations at the same time. For example, your program got two threads to run and your machine
4+
has two core. So you can run those threads in parallel.
5+
6+
A Parallel programming doesn't mean to be concurrent. Concurrency means running chunks of a program as individual
7+
executing tasks and producing right result.
8+
9+
## Synchronous program example
10+
11+
```xml
12+
func main() {
13+
print("zero")
14+
print("msi")
15+
}
16+
17+
func print(str string) {
18+
19+
for i := 0; i < 10; i++ {
20+
fmt.Println(str)
21+
time.Sleep(500)
22+
}
23+
}
24+
```
25+
26+
## Concurrent Program example 1:
27+
28+
29+
```xml
30+
31+
func main() {
32+
33+
go printStr("zero")
34+
printStr("msi")
35+
36+
}
37+
38+
func printStr(str string) {
39+
for i := 0; i < 50; i++ {
40+
fmt.Println(strconv.Itoa(i) + " " + str)
41+
time.Sleep(time.Second * 1)
42+
}
43+
44+
}
45+
46+
47+
```
48+
49+
50+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"time"
7+
)
8+
9+
func main() {
10+
11+
go printStr("zero")
12+
printStr("msi")
13+
14+
}
15+
16+
func printStr(str string) {
17+
for i := 0; i < 50; i++ {
18+
fmt.Println(strconv.Itoa(i) + " " + str)
19+
time.Sleep(time.Second * 1)
20+
}
21+
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
func main() {
9+
print("zero")
10+
print("msi")
11+
}
12+
13+
func print(str string) {
14+
15+
for i := 0; i < 10; i++ {
16+
fmt.Println(str)
17+
time.Sleep(time.Microsecond*1000)
18+
}
19+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /