IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Opened 21 years ago

Closed 20 years ago

Last modified 20 years ago

#586 closed enhancement (fixed)

Dynamic setting of thread safety in memory management

Reported by: Paul Price Owned by: David.Robbins@…
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 robert.desonia@…, 21 years ago

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

comment:2 by Paul Price, 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 robert.desonia@…, 20 years ago

Owner: changed from robert.desonia@… to David.Robbins@…

comment:4 by David.Robbins@…, 20 years ago

Resolution: fixed
Status: newclosed

I've added psMemThreadSafety as described here to turn off/(on) mutex locking.

comment:5 by Paul Price, 20 years ago

Resolution: fixed
Status: closedreopened

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:6 by Paul Price, 20 years ago

Oh, except psError which is fine.

comment:7 by David.Robbins@…, 20 years ago

Resolution: fixed
Status: reopenedclosed

ok. removed the thread safety in psList and p_psListThreadSafety.

comment:8 by Paul Price, 20 years ago

Keywords: VERIFIED added

Bug has been resolved.... closing.

comment:9 by Paul Price, 20 years ago

Keywords: VERIFIED removed

Bugs have been fixed... closing.

Note: See TracTickets for help on using tickets.