The Crystal Programming Language Forum

Documenting or indicating shard MT safety

How should shards indicate or document MT safety with or without -Dpreview_mt?

Some likely patterns:

  1. Fully MT safe
  2. Some classes MT safe
  3. Only safe for use within 1 Fiber at a time by design (Array. Hash)
  4. Unknown

Each of the above may or may not be tested or compatible with -Dpreview_mt.

This can be stated in the documentation of each type, indicating which guarantees are made that the data structure is safe for parallel or concurrent use.

Should there be annotations for:

  1. Thread safe (with or without -Dpreview_mt)
  2. Not safe. Don’t share. Possible indicators for Mutex wrap this method or Mutex wrap this object.
  3. Special: Read the documentation carefully

And further modifications to the documentation generator quickly indicating
:+1: - :-1: - :biohazard: - :question: (Safe - Single Fiber - Special - Unknown)

Maybe at a later point. I think first we need to get multithreading to be a fully supported feature.

Is there a list of MT issues where I can help?