githwxi / ATS-Postiats

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

libats/SATS/athread.sats lacks support for joinable pthreads #265

Closed okeuday closed 3 years ago

okeuday commented 3 years ago

Currently, all threads are created detached with PTHREAD_CREATE_DETACHED at: https://github.com/githwxi/ATS-Postiats/blob/7f5bea78c8849e730ca9b89bb513d25674b06ae5/libats/DATS/athread_posix.dats#L352-L362

By being detached the threads are not joinable which makes waiting for the termination of threads error-prone (a sleep after they are done processing should yield to allow them to complete assuming the OS scheduler is scheduling quickly, but joining is more dependable to ensure the thread stacks are freed). So, it would be helpful to have a way to ensure the athreads are joinable (in the interface for POSIX threads). It would be beneficial for things like memory leak checking (things that wait for program termination).

githwxi commented 3 years ago

The athread package was entirely an experiment in ATS2.

After getting a running implementation of ATS3, I would like to think about a new design for supporting threads in ATS3.