Question regarding pfree and thread safety. - Mailing list pgsql-hackers

From Thomas Hallgren
Subject Question regarding pfree and thread safety.
Date
Msg-id bu84oo$f42$1@news.hub.org
Whole thread Raw
Responses Re: Question regarding pfree and thread safety.
List pgsql-hackers
Is it safe to call pfree() from multiple threads?

My Java backend will need to utilize finalizers. Objects like a saved
execution plan that has been "forgotten" must be released when the wrapping
Java object is finalized to avoid memory leaks. The finalizer is called from
the garbage collector which in turn might run in a separate thread. I have
two choices:

1. Let finalizers put pfree() candiates on a "death row" and let each call
from SQL into my call manager pfree() the candidates found there. All "death
row" management is of course subject to a mutex.

2. Let the finalizer call pfree directly and trust that it is thread safe.

Advice is greatly appreciated.

- thomas




pgsql-hackers by date:

Previous
From: Joe Conway
Date:
Subject: Re: [GENERAL] Bug and/or feature? Complex data types in
Next
From: Richard Huxton
Date:
Subject: Re: Postgres v.7.3.4 - Performance tuning