File tree 2 files changed +16
-2
lines changed
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -12,17 +12,25 @@ var i = 0
12
12
13
13
func incrementing () {
14
14
//TODO: increment i 1000000 times
15
+ for i_inc := 0 ; i_inc < 1000000 ; i_inc ++ {
16
+ i ++
17
+ }
15
18
}
16
19
17
20
func decrementing () {
18
21
//TODO: decrement i 1000000 times
22
+ for i_dec := 0 ; i_dec < 1000000 ; i_dec ++ {
23
+ i --
24
+ }
19
25
}
20
26
21
27
func main () {
22
28
runtime .GOMAXPROCS (runtime .NumCPU ()) // I guess this is a hint to what GOMAXPROCS does...
23
29
// Try doing the exercise both with and without it!
24
30
25
31
// TODO: Spawn both functions as goroutines
32
+ go incrementing ()
33
+ go decrementing ()
26
34
27
35
// We have no way to wait for the completion of a goroutine (without additional syncronization of some sort)
28
36
// We'll come back to using channels in Exercise 2. For now: Sleep.
Original file line number Diff line number Diff line change 12
12
def incrementingFunction ():
13
13
global i
14
14
# TODO: increment i 1_000_000 times
15
+ for count in range (1000000 ):
16
+ i += 1
15
17
16
18
def decrementingFunction ():
17
19
global i
18
20
# TODO: decrement i 1_000_000 times
19
-
21
+ for count in range (1000000 ):
22
+ i -= 1
20
23
21
24
22
25
def main ():
23
26
# TODO: Something is missing here (needed to print i)
27
+ global i
24
28
25
29
incrementing = Thread (target = incrementingFunction , args = (),)
26
30
decrementing = Thread (target = decrementingFunction , args = (),)
27
31
28
32
# TODO: Start both threads
29
-
33
+ incrementing .start ()
34
+ decrementing .start ()
35
+
30
36
incrementing .join ()
31
37
decrementing .join ()
32
38
You can’t perform that action at this time.
0 commit comments