githwxi / ATS-Postiats

ATS2: Unleashing the Potentials of Types and Templates
www.ats-lang.org
Other
354 stars 54 forks source link

invalid read due to exceptions with threads #267

Closed okeuday closed 2 years ago

okeuday commented 3 years ago

When executing an executable with valgrind, it is able to detect an invalid read in threaded source code (using athreads/POSIX-threads) during an exception handling check. The output occurs in two separate threads at roughly the same time with:

Invalid read of size 8
my_atsexnframe_leave (pats_ccomp_exception.h:136)

I believe it is responsible for a SIGSEGV that occurs when the executable is ran without valgrind. The source code is: https://github.com/ats-lang/ATS-Postiats-release/blob/abca6113e4be7c7107b862312b993069dcc5d316/ccomp/runtime/pats_ccomp_exception.h#L136

You may already be aware of this issue. If you need to replicate it, I can provide instructions to recreate it.

githwxi commented 3 years ago

Yes, I am aware of this.

The implementation of exceptions in ATS2 is not thread-safe. The stack for handling exceptions is not thread-local; it is global. Therefore, only the main thread can make use of exceptions in ATS2.

okeuday commented 3 years ago

@githwxi Ok, thank you for confirming that is the situation. I can avoid the problem.