Skip to content

support loops wrapped by Threads.@threads #38

Description

@mileslucas

It would be nice if the @progress macro were thread-safe and supported the Threads.@threads macro call.

This would require a bit of a rewrite, since the current _progress function does not update the fraction in a thread-safe manner, so a small rewrite would have to take place to change the fraction variables to use atomics. In my own code, the following has worked in a thread-safe manner-

@withprogress begin
	it = Threads.Atomic{Int}(0)
	N = length(iter)
	Threads.@threads for i in N
		# body
		Threads.atomic_add!(it, 1)
		@logprogress it[] / N
	end
end

Parsing the input should be as simple as

if ex.head == :macrocall && ex.args[1] == :(Threads.var"@threads")
	_forloop = ex.args[2:end]
	# ...

I'm not really sure what is required beyond that to make it work, or I would have given it a shot myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions