:This will require that stdio.h includes pthread.h.
:
:David Xu
Ah. Well, in that case we will have to deal with the race by enclosing
the allocation of the mutex within another, fixed mutex, and then
checking to see if the FILE's mutex is still NULL.
if (fp->blah_mutex is NULL) {
get_a_fixed_mutex(&fixed_mutex);
if (fp->blah_mutex is still NULL) {
fp->blah_mutex = malloc ....
init ....
}
rel_a_fixed_mutex(&fixed_muteX);
}
That would still be reasonably optimal. If you wanted to parallelize
it 'fixed_mutex' could be a selected mutex out of a fixed array based
on a simple hash of the FILE pointer.
-Matt
Matthew Dillon
<dillon@xxxxxxxxxxxxx>