src/ThreadUtil.jl

Tue, 07 Dec 2021 11:41:07 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 07 Dec 2021 11:41:07 +0200
changeset 34
22a64e826ee7
parent 33
a60d2f12ef93
permissions
-rw-r--r--

New logger and iteration interface

###########################
# 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