Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Apr 2010 11:07:49 +0100
From:      Martin Simmons <martin@lispworks.com>
To:        freebsd-threads@freebsd.org
Subject:   Re: Advice / best practice - thread connection pools / mutexes
Message-ID:  <201004271007.o3RA7nLK021467@higson.cam.lispworks.com>
In-Reply-To: <6AD0A971B01FA1DE632BAF65@HPQuadro64.dmpriest.net.uk> (message from Karl Pielorz on Tue, 27 Apr 2010 09:00:35 %2B0100)
References:  <6AD0A971B01FA1DE632BAF65@HPQuadro64.dmpriest.net.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
Assuming it is safe share MySQL connections between threads like that (I don't
know), then using a data structure to track the unused connections sounds like
the simplest approach.

Protect access to the data structure with a mutex and use a condition variable
to wait (with pthread_cond_wait) for a free connection if they are all in use.

When a connection is freed, use pthread_cond_signal to wake a waiting thread.
Note that both pthread_cond_wait and pthread_cond_signal must be called while
holding the mutex to prevent missed wakups.

__Martin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201004271007.o3RA7nLK021467>