ta0kira / zeolite

Zeolite is a statically-typed, general-purpose programming language.
Apache License 2.0
18 stars 0 forks source link

Make atomic operations in the language thread-safe in the C++ output. #9

Closed ta0kira closed 4 years ago

ta0kira commented 4 years ago

As long as the only object state is data members and static parameters, and (future) lambdas don't use C++ references in closures, everything else should be fine.

ta0kira commented 4 years ago

This might also require changing SourceContext and CleanupContext to use ScopedCapture instead of AutoThreadCrosser so that tracing doesn't cause a segfault in threads.

Rather than using ThreadCrosser::WrapCall in the lambda implementation (see #6), a new TraceContext could be created to copy the previous trace. While potentially inefficient, setting -DDISABLE_TRACING during C++ compilation would completely eliminate the cost. (There might also need to be a distinction between the "creation trace" and the "execution trace" for lambdas.)

ta0kira commented 4 years ago

All remaining thread-safety issues in generated code relate to overwriting value references. Since std::shared_ptr is thread-safe (as far as memory management), this means that race-conditions shouldn't cause undefined behavior, except possibly in hand-written C++ code with persistent C++ state, e.g., std::ostringstream.