Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This code may never terminate, as each thread may acquire one lock and wait for the other lock to be released by the other thread. To avoid deadlock, one possible solution is to use a single lock for both variables, or to acquire the locks in the same order in both threads.

Conclusion

In conclusion, Universal Extensions run in a multithreaded environment.  In most cases, the complexity of multithreading is transparent to the extension developer and no special action is required to deal with it.  However, under certain scenarios, like when using in-process Dynamic Commands, the extension developer may have to take special precautions to ensure their code will perform in a thread safe manner.  The sections above discuss the most common issues that may be encountered in such a scenario and ways to deal them. This is by no means a complete reference on the topic and the developer is encouraged to seek additional sources for a more complete understanding of multithreading programming in Python.