aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/examples/concurrency/concurrency.v
blob: 92a5517e869ab66e44566552e6bb1d0152691811 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import time

// Simulate expensive computing using sleep function
fn expensive_computing(id int, duration int) {
	println('Executing expensive computing task ($id)...')
	time.sleep(duration * time.millisecond)
	println('Finish task $id on $duration ms')
}

fn main() {
	mut threads := []thread{}
	threads << go expensive_computing(1, 100)
	threads << go expensive_computing(2, 500)
	threads << go expensive_computing(3, 1000)
	// Join all tasks
	threads.wait()
	println('All jobs finished!')
}