Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Does the spec mandate thread safety? (I guess I should ask if there's a spec or is MRI the reference implementation)


AFAIK there is no spec. MRI is the reference implementation, but many things are experimental or intentionally unspecified.

Given that MRI ships with a GIL, the only core classes that are intentionally aware of multi-threading concerns are Mutex, ConditionVariable, and Queue.


A GIL does not mean classes should ignore concurrency concerns, it's still possible to get odd behaviour from things like hash table implementations in a GIL based interpreter when inserting objects as you may end up thread switching mid operation.

What saves you most of the time is that it isn't worth switching threads too often so normally you get lucky.


Even a thread-aware collection where collection methods are synchronized on an internal lock (as in Java 1.0 — this was quickly dropped as it's effectively useless) wouldn't help here: having `[]` and `[]=` safe will not make calling `[]`, performing an addition and then calling `[]=` safe.


There is an ISO spec, but it's not really relevant to the future of the language.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: