Multithreading in julia 1.1

#1

Hello everyone,

I have a little problem:
2 functions

function fa(x)
	for i=1:x
		println("Thread1: $i")
		sleep(1)
	end
end

function fb(x)
	for i=1:x
		println("Thread2: $i")
		sleep(1)
	end
end

How to run these 2 functions in the same time (multithreading) ?

Thank you in advance !

#2

Use @async:

@async(fa(1)); @async(fb(1))
#3

@async will not run them on separate threads but, as the macro name implies, just run them asynchronously.

Currently, the threading support in Julia is not suitable for spawning heterogeneous tasks working independently. The @threads macro can however be used to run a loop threaded. Support for spawning tasks on different threads is work in progress.

1 Like
#4

Ok, thank you verry much!

#5

I already do this but it show me nothing.
I expected to show me something like this:
Thread1: 1
Thread2: 1
Thread1: 2
Thread2: 2
Thread1: 3
Thread2: 3

but nothing

#6

IO in threaded loops is not supported on 1.1. A limited amount of IO should be supported in 1.2 which will be released in a while.