Skip to content

Commit

Permalink
Fix @threadcall argument passing.
Browse files Browse the repository at this point in the history
Fixes JuliaLang#17819. Also document not being allowed to call back into Julia.
  • Loading branch information
maleadt authored and mfasi committed Sep 5, 2016
1 parent cb3c2bb commit afc95ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/threadcall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function without causing the main `julia` thread to become blocked. Concurrency
is limited by size of the libuv thread pool, which defaults to 4 threads but
can be increased by setting the `UV_THREADPOOL_SIZE` environment variable and
restarting the `julia` process.
Note that the called function should never call back into Julia.
"""
macro threadcall(f, rettype, argtypes, argvals...)
# check for usage errors
Expand Down Expand Up @@ -73,6 +75,7 @@ function do_threadcall(wrapper::Function, rettype::Type, argtypes::Vector, argva
y = cconvert(T, x)
push!(roots, y)
unsafe_store!(convert(Ptr{T}, ptr), unsafe_convert(T, y))
ptr += sizeof(T)
end

# create return buffer
Expand Down
4 changes: 4 additions & 0 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ threadcall_test_func(x) =
@test threadcall_test_func(3) == 1
@test threadcall_test_func(259) == 1

f17819(a,b) = Cint(a+b)
cf17819 = cfunction(f17819, Cint, (Cint,Cint))
@test @threadcall(cf17819, Cint, (Cint, Cint), 1, 2) == 3

let n=3
tids = Culong[]
@sync for i in 1:10^n
Expand Down

0 comments on commit afc95ab

Please sign in to comment.