Next: 1.11 Optimization Up: 1.10 Threads Previous: 1.10.1 Implicit synchronization Contents Index

## 1.10.2 General threading concerns

Onyx's basic threading mechanisms are typical of those found in modern threading implementations. One of the aspects of Onyx's threading implementation to be aware of is that since the operating system's threading implementation is used, there are many types of programming errors that can cause undefined behavior. With some effort, it is possible to crash the Onyx interpreter without the use of threads. However, it requires skill and discipline to not crash the Onyx interpreter when using threads. This was a conscious design decision for Onyx; doing otherwise would have limited the scalability of threading.

Now prepare for some discouraging pontification on why threaded programming is generally harmful. In the author's experience, the vast majority of developers do not have a solid enough grasp of threading concepts to be seriously engaging in the practice. As a first step to becoming proficient at threaded programming, much reading and thought are necessary. The next step is to implement several non-trivial threaded programs that are doomed to be complete disasters. After that, it may be possible for a programmer to write threaded programs that do the right thing most of the time. However, even the most skilled developers still will be unable to consistently write code that is free of race conditions, deadlocks, livelocks, locksteps, etc. Finally, there are some developers who, despite being otherwise proficient, will never obtain a solid grasp of threaded programming, regardless of how many times the basic concepts are reviewed.

In summary, don't use threads unless there are significant measurable gains in performance or code complexity. Otherwise, threaded programming just is not worth the unavoidable pain that it inflicts.

Next: 1.11 Optimization Up: 1.10 Threads Previous: 1.10.1 Implicit synchronization Contents Index