Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@threads Macro triggers Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ffd71124580 #52287

Closed
BenitoEck opened this issue Nov 23, 2023 · 3 comments
Closed

Comments

@BenitoEck
Copy link

BenitoEck commented Nov 23, 2023

This exception is triggered and (locally) reproducibly by the use of the @threads macro with the for loop below and does not occur when either the macro call is omitted or the range of the iteration is lowered e.g. from 1:10^8 to 1:10^3 although the system does not seem to run out of memory. 4 Threads were given to Julia 1.9.3 installed via Windows installer from julia.org Loaded at startup was only OhMyREPL via startup file and REPL was started from Windows PowerShell in the MS "Terminal" App with -q flag given for better readability. Julia started with 3 threads instead of 4 triggers for the same code this shorter exception message as follows: Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ffd71124580 -- before exiting to PowerShell and withouth -q give the slightly longer:

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks. Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ffd7112458e -- memcpy at C:\WINDOWS\System32\msvcrt.dll (unknown line) in expression starting at REPL[3]:1 memcpy at C:\WINDOWS\System32\msvcrt.dll (unknown line) aligned_offset_realloc at C:\WINDOWS\System32\msvcrt.dll (unknown line)

System Information:
Windows 10 Home Version 22H2
Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz 1.80 GHz 8 GB RAM

Full console output below:

`PS C:\Users\benja> julia -q --threads 4
julia> using Base.Threads

julia> v = []
Any[]

julia> @threads for i in 1:10^8
i = i^2
i = sqrt(i)
push!(v,i)
end

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0xION_ACCESS_VIOLATION with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0xION_ACCESS_VIOLATION with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ffd7112458e -- at 0x7ffd7112458e -- at 0x7ffd7112458e -- memcpy at C:\WINDOWS\System32\msvcrt.dll (unknown line)
in expression starting at REPL[3]:1
memcpy at C:\WINDOWS\System32\msvcrt.dll (unknown line)
aligned_offset_realloc at C:\WINDOWS\System32\msvcrt.dll (unknown line)
memcpy at C:\WINDOWS\System32\msvcrt.dll (unknown line)
l.dll (unknown line)
in expression starting at REPL[3]:1
RtlGetCurrentServiceSessionId at C:\WINDOWS\SYSTEM32\ntdin expression starting at REPL[3]:1
in expression starting at REPL[3]:1
INDOWS\SYSTEM32\ntdll.dll (unknown line)
memcpy at C:\WINDOWS\System32\msvcrt.dll (unknown line)
RtlFreeHeap at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
aligned_offset_realloc at C:\WINDOWS\System32\msvcrt.dll (unknown line)
free at C:\WINDOWS\System32\msvcrt.dll (unknown line)
aligned_offset_realloc at C:\WINDOWS\System32\msvcrt.dll (unknown line)
jl_realloc_aligned at C:/workdir/src\gc.c:357 [inlined]
gc_managed_realloc_ at C:/workdir/src\gc.c:4041
lined]
gc_managed_realloc_ at C:/workdir/src\gc.c:4041
gc_managed_realloc_ at C:/workdir/src\gc.c:4041
lined]
gc_managed_realloc_ at C:/workdir/src\gc.c:4041
gc_managed_realloc_ at C:/workdir/src\gc.c:4041
ijl_gc_managed_realloc at C:/workdir/src\gc.c:4058
ijl_gc_managed_realloc at C:/workdir/src\gc.c:4058
ijl_gc_managed_realloc at C:/workdir/src\gc.c:4058
array_resize_buffer at C:/workdir/src\array.c:672
array_resize_buffer at C:/workdir/src\array.c:672
array_resize_buffer at C:/workdir/src\array.c:672
jl_array_grow_at_end at C:/workdir/src\array.c:893
jl_array_grow_at_end at C:/workdir/src\array.c:893
jl_array_grow_at_end at C:/workdir/src\array.c:893
unknown function (ip: 00007ffcf17b03ba)
unknown function (ip: 00007ffcf17b0459)
unknown function (ip: 00007ffcf17b0459)
macro expansion at .\REPL[3]:4 [inlined]
#42#threadsfor_fun#5 at .\threadingconstructs.jl:200
#42#threadsfor_fun at .\threadingconstructs.jl:167 [inlined]
#1 at .\threadingconstructs.jl:139
unknown function (ip: 00000233b3c22653)
jl_apply at C:/workdir/src\julia.h:1880 [inlined]
start_task at C:/workdir/src\task.c:1092
Allocations: 637881 (Pool: 637023; Big: 858); GC: 1
jfptr_pushNOT._54173.clone_1 at C:\Users\benja\AppData\Local\Programs\julia-1.9.3\lib\julia\sys.dll (unknown line)
_growend! at .\array.jl:1014 [inlined]
push! at .\array.jl:1068
push! at .\array.jl:1068
3]:4 [inlined]
#42#threadsfor_fun#5 at .\threadingconstructs.jl:200
#42#threadsfor_fun at .\threadingconstructs.jl:167 [inlined]
#1 at .\threadingconstructs.jl:139
unknown function (ip: 00000233b3c22653)
jl_apply at C:/workdir/src\julia.h:1880 [inlined]
start_task at C:/workdir/src\task.c:1092
Allocations: 637881 (Pool: 637023; Big: 858); GC: 1
PS C:\Users\benja>`

@KristofferC
Copy link
Member

push! to an array from multiple threads is not valid.

@BenitoEck
Copy link
Author

Hey Kristoffer, thanks for looking into it! For me, planting the marco there seems such a natural (also lazy) thing to do and the kind of trouble it causes somehow depends on the range you give to it. Does this deserve a proper warning because it could be something a lot of people run into and then get prompted to send a bug report, or do you want to close this issue? I'm fine with both.

@KristofferC
Copy link
Member

the kind of trouble it causes somehow depends on the range you give to it

There is always trouble, it's just that when you have a big range you are lucky in that Julia crashes so you see the trouble.

Does this deserve a proper warning

This case is already specified in the multi threading docs:

Base collection types require manual locking if used simultaneously by multiple threads where at least one thread modifies the collection (common examples include push! on arrays, or inserting items into a Dict).

so I think this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants