Hi,
This is a toy program that draw circles on the Julia logo. It woks sequentially but when I try to do parallel image processing I have this error with Julia 1.5.3 up to date.
Is it because the cairo library cannot be used by multiple threads or am I doing something wrong ?
Thanks !
file main.jl
using Luxor
include("proc.jl")
Threads.@threads for i in 1:10
#for i in 1:10
process(i)
end
file proc.jl
function process(i)
image = readpng("Julia_Logo.png")
println(i, " image read")
w = image.width
h = image.height
# file output
fname = "image$i.png"
Drawing(w, h, fname)
placeimage(image, 0, 0)
setcolor((255,0,0,0.3))
for x in 1:50
x1 = rand()*w
y1 = rand()*h
circle(Point(x1, y1), 12, :fill) # draw a circle on the image
end
finish()
end
I tried to put a lock() at the final step of image processing :
function process(i)
image = readpng("Julia_Logo.png")
println(i, " image read")
w = image.width
h = image.height
# file output
fname = "results/image$i.png"
Drawing(w, h, fname)
placeimage(image, 0, 0)
setcolor((255,0,0,0.3))
for x in 1:50
x1 = rand()*w
y1 = rand()*h
circle(Point(x1, y1), 5, :fill) # draw a circle on the image
end
begin
lock(a)
try
finish(a)
finally
unlock(a)
end
end
end
there is a little improvement, some images are processed in parallel, but there is still a race problem related to the library Cairo