Skip to content

Commit 93cf8f5

Browse files
author
msol
committed
fix a bug related to behavior change in @threads
1 parent 48f5336 commit 93cf8f5

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

src/util.jl

+41-16
Original file line numberDiff line numberDiff line change
@@ -838,26 +838,51 @@ _todate(::Any) = throw(ArgumentError("DateFormat must be a string or a DateForma
838838
end
839839

840840
function parse_eachrow(problems::Vector{Bool}, ::Type{T}, x::Vector, buffer::LineBuffer, idx::Matrix{Tuple{UInt32, UInt32}}, j::Int, informat::Union{Nothing, Vector{Ptr{Nothing}}}, df, char_buff, int_bases::Int, string_trim::Bool, threads::Bool) where T
841-
InMemoryDatasets.@_threadsfor threads for i in 1:length(x)
842-
if idx[i, j][1] == 0
843-
x[i] = missing
844-
else
845-
new_lo::Int = idx[i,j][1]
846-
new_hi::Int = idx[i,j][2]
847-
if informat !== nothing
848-
# if informat !== nothing, it is a pointer
849-
for ptrs in informat
850-
(new_lo, new_hi) = ccall(ptrs, Tuple{Int, Int}, (Vector{UInt8}, Int, Int), buffer.data, new_lo, new_hi)
841+
if threads
842+
Threads.@threads :static for i in 1:length(x)
843+
if idx[i, j][1] == 0
844+
x[i] = missing
845+
else
846+
new_lo::Int = idx[i,j][1]
847+
new_hi::Int = idx[i,j][2]
848+
if informat !== nothing
849+
# if informat !== nothing, it is a pointer
850+
for ptrs in informat
851+
(new_lo, new_hi) = ccall(ptrs, Tuple{Int, Int}, (Vector{UInt8}, Int, Int), buffer.data, new_lo, new_hi)
852+
end
853+
idx[i,j] = (new_lo, new_hi)
851854
end
852-
idx[i,j] = (new_lo, new_hi)
855+
if char_buff !== nothing
856+
charbuff = char_buff[Threads.threadid()]
857+
else
858+
charbuff = nothing
859+
end
860+
861+
x[i] = buff_parser_ind(problems, i, buffer, Int(new_lo), Int(new_hi), df, charbuff, int_bases, string_trim, T)
853862
end
854-
if char_buff !== nothing
855-
charbuff = char_buff[Threads.threadid()]
863+
end
864+
else
865+
for i in 1:length(x)
866+
if idx[i, j][1] == 0
867+
x[i] = missing
856868
else
857-
charbuff = nothing
858-
end
869+
new_lo::Int = idx[i,j][1]
870+
new_hi::Int = idx[i,j][2]
871+
if informat !== nothing
872+
# if informat !== nothing, it is a pointer
873+
for ptrs in informat
874+
(new_lo, new_hi) = ccall(ptrs, Tuple{Int, Int}, (Vector{UInt8}, Int, Int), buffer.data, new_lo, new_hi)
875+
end
876+
idx[i,j] = (new_lo, new_hi)
877+
end
878+
if char_buff !== nothing
879+
charbuff = char_buff[Threads.threadid()]
880+
else
881+
charbuff = nothing
882+
end
859883

860-
x[i] = buff_parser_ind(problems, i, buffer, Int(new_lo), Int(new_hi), df, charbuff, int_bases, string_trim, T)
884+
x[i] = buff_parser_ind(problems, i, buffer, Int(new_lo), Int(new_hi), df, charbuff, int_bases, string_trim, T)
885+
end
861886
end
862887
end
863888
nothing

0 commit comments

Comments
 (0)