#586 closed enhancement (fixed)
Dynamic setting of thread safety in memory management
| Reported by: | Paul Price | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | sys | Version: | unspecified |
| Severity: | minor | Keywords: | |
| Cc: |
Description
Discussions at the IfA have resulted in a modified requirement on the thread
safety: we'd like to be able to turn it off. The reason for this is that we
have found that some programs (specifically, those which are intensive on memory
allocation) are dramatically slowed by the mutex locking --- mutex operations
topped the charts of code profiles (around 25%!). Because of this, we specify a
static boolean within the memory handling code that is to be tested before any
mutex operation is performed (we reason that the check is much less expensive
than the mutex operation, so it has negligible impact). The default behaviour
is that mutex operations *are* performed, but they can be turned off by calling
psMemThreadSafety(false).
The section in the SDRS is below:
\subsubsection{Thread safety}
Locking a mutex is an expensive operation that can dramatically impact
the efficiency of a program for the worse. When the user is not
concerned with multiple threads, this is a needless waste, and so we
specify that the thread safety in the memory management system may
be deactivated (and activated) dynamically.
\begin{prototype}
bool psMemThreadSafety(bool safe);
\end{prototype}
\code{psMemThreadSafety} shall turn on thread safety in the memory
management functions if \code{safe} is \code{true}, and deactivate all
mutex locking in the memory management functions if \code{safe} is
\code{false}. The function shall return the previous value of the
thread safety.
Note that the default behaviour of the library shall be for the
locking to be performed.
Change History (9)
comment:1 by , 21 years ago
comment:2 by , 21 years ago
Yes, I think creating the mutex is fine (that's a once-off operation, right?),
but it's not used if thread safety is turned off.
We would prefer this not be done via autoconf, since that would then require
having two versions of the library coexisting on the same machine, which is a
bit of a headache.
I thought about putting it into psLibInit (and we can do that), but I thought
that since the user might want to turn it off for a period before turning it
back on, that psLibInit shouldn't be the sole switch.
comment:3 by , 20 years ago
| Owner: | changed from to |
|---|
comment:4 by , 20 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
I've added psMemThreadSafety as described here to turn off/(on) mutex locking.
comment:5 by , 20 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
I see that there is also a p_psListThreadSafety. There is no need for built-in
thread safety in psList (or any other structure apart from the memory
management), and it is not in the SDRS --- please remove it.
comment:7 by , 20 years ago
| Resolution: | → fixed |
|---|---|
| Status: | reopened → closed |
ok. removed the thread safety in psList and p_psListThreadSafety.

Would I still create the mutex and just not use it if thread safety is off? If I don't, we'd have problems if
it was turned on again, oui?
This could also be accomplished via autoconf at compile time; would that be better? In that case, the
user wouldn't need to turn it off/on in their code.
Also, have you considered just integrating this into the psLibInit function? Seems like that option would
make some sense as well.
-rdd