forked from pkolaczk/async-runtimes-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from themantra108/themantra108-patch-1
Add files via upload
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function task_function() | ||
sleep(10) | ||
end | ||
|
||
function main() | ||
# Check if the number of tasks is provided as a command line argument | ||
if length(ARGS) < 1 | ||
println("Usage: julia concurrent_tasks.jl <num_tasks>") | ||
return | ||
end | ||
|
||
# Get the number of tasks from the command line argument | ||
num_tasks = parse(Int, ARGS[1]) | ||
|
||
# Spawn concurrent tasks | ||
tasks = Vector{Task}(undef, num_tasks) | ||
for i in 1:num_tasks | ||
tasks[i] = @async task_function() | ||
end | ||
|
||
# Wait for all tasks to finish | ||
for task in tasks | ||
wait(task) | ||
end | ||
|
||
println("All tasks have finished.") | ||
end | ||
|
||
stats = @timed main() |