On Sat, 8 Feb 2003, Eric Hodel wrote:

> ah-ha!  You really want #synchronize, it does the waiting for you, and
> its not a busy-wait.
>
> class DistributedObject
>   def method
>     sem.synchronize { yield }
>   end
> end

not in my case actually :  i have an Array of PGconns, iff i cannot obtain the
lock on _any_ of them, i must go to sleep on a ConditionVarible and am woken
up appropriately (when a connection becomes free).  eg.  there is a Mutex for
each connection AND a Mutex on the array of connections.  the threads which
release the lock on a particular connection also notify the condition
variable.  in that way, i DO use the non-busy-wait feature of sem.synchronize
_but_ this is wrapped around the entire array of connections.  now, if i used
sem.synchronize on conns[0], for example, conn[1] would never be used!  eg. i
cannot _automatically_ go to sleep just because a _particular_ conn is not
available.  i only should go to sleep in _all_ connections are not available.
does that make any sense?


> (I hadn't realized that try_lock worked this way, I thought it just told
> you if the lock was available or not... learn something new every day :)

very handy in the above case - sometimes you want to continue doing
_something_ even if you could not aquire the lock (like trying to obtain
_another_ one)

> For one, I'd push the lock as deep as you can get it, no sense locking
> when you're not doing something that needs to update protected state
> (say, reading or writing a file, calculating statistics, etc.).

PGconn's are not thread safe, so _any_ accesses to them must be protected.
unfortunately, this is not that 'deep'... ;-(

> As for the real problem here, I'll defer to the rest of the crowd, I
> don't feel experienced enough to give such advice :)

well - anyone else? ;-)


-a


>
> --=20
> Eric Hodel - drbrain / segment7.net - http://segment7.net
> All messages signed with fingerprint:
> FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04
>
>
> --Tg5qL4DubmxJEzuM
> Content-Type: application/pgp-signature
> Content-Disposition: inline
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.0 (FreeBSD)
>
> iD8DBQE+Q+mvMypVHHlsnwQRAj+bAJ47o9V87J/9C3OXXD5WYnih1XnMBgCfew04
> dNYvUaZAGxyP/jkcZameSLk=
> =XV8j
> -----END PGP SIGNATURE-----
>
> --Tg5qL4DubmxJEzuM--
>
>

-- 

 ====================================
 | Ara Howard
 | NOAA Forecast Systems Laboratory
 | Information and Technology Services
 | Data Systems Group
 | R/FST 325 Broadway
 | Boulder, CO 80305-3328
 | Email: ahoward / fsl.noaa.gov
 | Phone:  303-497-7238
 | Fax:    303-497-7259
 ====================================