Subject: | Threading issues |
Testing with threads fails on some machines. NetBSD consistently,
OpenBSD inconsistently. Cygwin on the latest versions.
They work fine on Linux, Darwin, Solaris, Strawberry Win32, and some others.
The #perl wisdom is "screw threads, never test with them, and disregard
all bug reports where the user was using threads." This seems harsh for
a library that ought to be able to be used in a threaded environment.
I believe the underlying issue is a particular issue with pthreads
mutexes. The primes cache is managed by a readers/writers solution, and
mutexes are used. At some point we get this scenario:
A reads: lock access mutex. reader_count++. read... read...
B reads: reader_count++. read... read...
A done: reader_count--.
B done: reader_count--. unlock access mutex.
The issue is that thread A did the lock, and thread B did the unlock.
This is undefined behavior, and the BSD's are being strict about
ownership. The cache.c code needs to move to using pthread_cond_* for
management.