scheme_mutex_t now uses volatile keyword for owner and count fields

because these fields can be accessed from multiple threads concurrently.
Updated $yield and $thread-check in mats/thread.ms to be more tolerant of timing variability.

original commit: 0a6a1e14e7ecb9e39fa7a10a8584ed2fec24cbf4
This commit is contained in:
Bob Burger 2016-06-22 15:33:21 -04:00
parent d14d167275
commit 51db0ddbc1
4 changed files with 15 additions and 4 deletions

5
LOG
View File

@ -248,3 +248,8 @@
io.ms
- fixed typo: VC/bin/vcvars64.bat => VC/bin/amd64/vcvars64.bat
c/Mf-a6nt, c/Mf-ta6nt
- scheme_mutex_t now uses volatile keyword for owner and count fields
because these fields can be accessed from multiple threads
concurrently. Updated $yield and $thread-check in mats/thread.ms to
be more tolerant of timing variability.
c/types.h, mats/thread.ms, release_notes.stex

View File

@ -277,8 +277,8 @@ typedef struct _bucket_pointer_list {
#ifdef PTHREADS
typedef struct {
s_thread_t owner;
uptr count;
volatile s_thread_t owner;
volatile uptr count;
s_thread_mutex_t pmutex;
} scheme_mutex_t;

View File

@ -94,11 +94,11 @@
(define $fib (lambda (x) (if (< x 2) 1 (+ ($fib (- x 1)) ($fib (- x 2))))))
(define $nthreads 1)
(define $yield
(let ([t (make-time 'time-duration 1000 0)])
(let ([t (make-time 'time-duration 1000000 0)])
(lambda () (sleep t))))
(define $thread-check
(lambda ()
(let loop ([n 10] [nt (length ($threads))])
(let loop ([n 100] [nt (length ($threads))])
(cond
[(<= nt $nthreads)
(set! $nthreads nt)

View File

@ -1474,6 +1474,12 @@ On Windows, the inliner has been fixed to handle \scheme{wchar} and
On Windows, the path-related procedures now raise an appropriate exception when the path argument is not a string.
\subsection{Internal mutex structure not always thread safe (9.4)}
The internal mutex structure now has its fields marked
\scheme{volatile} so that the C compiler does not reorder assignments
to these fields.
\subsection{\protect\scheme{dynamic-wind} mistakenly enabling interrupts (9.3.3)}
A bug causing \scheme{dynamic-wind} to unconditionally enable