-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
threadid() and nthreads() usage #265
Comments
Oops, we ought to think this through. I have used the thread features some on Julia 1.9 and did not notice any issues. |
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
I think I found some issues: #321 |
I have a proposal to handle the Luxor context problem of parallel programming. It is to allow the user to pass a context object to all the relevant functions. I admit that it would be a big refactoring, but it will be worth it. Here is my proposal: At first, we should define (within Luxox) a new type for the context object, say struct Context
saved_colors::Tuple{Float64, Float64, Float64, Float64}[]
CURRENTDRAWING::Array{Drawing, 1}()
CURRENTDRAWINGINDEX::Ref{Int}
end
function drawing_context(*a)
ctx = Context([], [], Ref(0))
push!(ctx.CURRENTDRAWING, Drawing(*a))
return ctx
end Secondly, we should add a new verison method that takes a After that, users can do the following: ctx = drawing_context(1000, 1000)
origin(ctx)
fontsize(ctx, 50)
text(ctx, "hello world")
finish(ctx) Additionally, if we also have a magic macro, say @context 1000 1000 begin
origin()
fontsize(50)
text("hello world")
finish()
end The old |
Whatever its merits, I think this change is too big, and goes against the spirit of Luxor being simple (and not using Cairo contexts…!). I would prefer to see Luxor being single-threaded than becoming more complex. Perhaps Makie.jl is a more suitable location for more complex multi-threaded code. |
Here is another solution that can make Luxor mutable struct Drawing
width::Float64
...
strokescale::Bool
saved_color_stack::Vector{NTuple{4,Float64}}
... Secondly, we should rewrite every drawing function. Pass a Drawing object to the function as its keyword argument, and set the global implicit Drawing object as the default value, says, function origin(pt; drawing=_get_current_drawing_save())
setmatrix([1.0, 0.0, 0.0, 1.0, 0.0, 0.0]; drawing=drawing)
Cairo.translate(drawing.cr, pt.x, pt.y)
end
function gsave(; drawing=_get_current_drawing_save())
Cairo.save(drawing.cr)
r, g, b, a = (drawing.redvalue, drawing.greenvalue, drawing.bluevalue, drawing.alpha)
push!(drawing.saved_color_stack, (r, g, b, a))
return (r, g, b, a)
end After that, users can do the following: function my_spawnable_function(i=0)
filename = "$i.png"
d = Drawing(1000, 1000, filename)
origin(; drawing=d)
fontsize(50; drawing=d)
text(filename; drawing=d)
finish(; drawing=d)
end
fetch.(Threads.@spawn my_spawnable_function(i) for i in 1:10)
# old-style function counterpart that without `drawing=d` will only output 4 pngs if you launch julia with `julia -t 4`,
# whatever in old version Luxor or new proposal version here. Again, a convenient macro Although it's not a breaking change, it is still a big change. Almost all the functions need to be rewritten. |
From this blog post we read that:
In Luxor
threadid()
does appear a few times:Luxor.jl/src/drawings.jl
Line 90 in 18d96c8
Luxor.jl/src/basics.jl
Line 553 in 18d96c8
so there might be the possibility of issues and/or bugs.
The text was updated successfully, but these errors were encountered: