src/ThreadUtil.jl

Wed, 15 Dec 2021 01:09:09 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Wed, 15 Dec 2021 01:09:09 +0200
changeset 36
6dfa8001eed2
parent 33
a60d2f12ef93
permissions
-rw-r--r--

Implement ZipArrays

###########################
# Some threading utilities
###########################

__precompile__()

module ThreadUtil

##############
# Our exports
##############

export @threadsif,
       @background,
       @backgroundif


##########
# Threads
##########

macro threadsif(threads, loop)
    return esc(:(if $threads
                    Threads.@threads $loop
                else
                    $loop
                end))
end

macro background(bgtask, fgtask)
    return :(t = Threads.@spawn $(esc(bgtask));
             $(esc(fgtask));
             wait(t))
end

macro backgroundif(threads, bgtask, fgtask)
    return :(if $(esc(threads))
                @background $(esc(bgtask)) $(esc(fgtask))
            else
                $(esc(bgtask))
                $(esc(fgtask))
            end)
end

end # Module

mercurial