Drb and signals

if one has an object with a method similar to

class DistributedObject
def method
Thread.pass while sem.try_lock
yield
ensure
sem.unlock
end
end

and the client process gets (for instance) a sigabrt, the lock will not be
released - causing the server process to freeze. is there anything that can
be done on the server to remedy this, or must it be done on the client only?
if so which signals should be dealt with and in what manner?

thanks.

-a

···

====================================

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
====================================

if one has an object with a method similar to

class DistributedObject
def method
Thread.pass while sem.try_lock
yield
ensure
sem.unlock
^^^

Where is this getting locked?

end
end

and the client process gets (for instance) a sigabrt, the lock will not be
released - causing the server process to freeze. is there anything that can
be done on the server to remedy this, or must it be done on the client only?
if so which signals should be dealt with and in what manner?

You could install a signal handler that would unlock the Mutex, but I’m
not sure how much work would be involved to make it always do the right
thing, as you need to know that you locked it and not some other
client (this may or may not be a problem)

Why are you getting the sigabrt, anyway?

···

ahoward (ahoward@fsl.noaa.gov) wrote:


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

class DistributedObject
def method
Thread.pass while sem.try_lock
yield
ensure
sem.unlock
^^^

Where is this getting locked?

from the pickaxe :

try_lock : ref.try_lock → true or false

Attempts to obtain the lock and
returns immediately. Returns true if
the lock was granted.

so the thread yield control until the lock is granted.

You could install a signal handler that would unlock the Mutex, but I’m
not sure how much work would be involved to make it always do the right
thing, as you need to know that you locked it and not some other
client (this may or may not be a problem)

this is not possible for the reasons you mention.

Why are you getting the sigabrt, anyway?

because i am doing a ‘ctrl-c’ from the client tty. i am trying to make my
class super bomber. with this exception - it seems to be.

in general, i am trying to learn what happens in a drb server when a client
aborts or is otherwise terminated prematurely (eg. before the method has
finished completing)

-a

···

On Sat, 8 Feb 2003, Eric Hodel wrote:

–=20
Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

–lBR2yNlwcY132B3M
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (FreeBSD)

iD8DBQE+Q9xuMypVHHlsnwQRAggbAJ9MZT4CUCRPmCqiUR9jY6TGtd3TNgCbBeqo
POIOV/XIRGZP2T4LWPu728Y=
=P39E
-----END PGP SIGNATURE-----

–lBR2yNlwcY132B3M–

====================================

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
====================================

class DistributedObject
def method
Thread.pass while sem.try_lock
yield
ensure
sem.unlock
^^^

Where is this getting locked?

from the pickaxe :

try_lock : ref.try_lock → true or false

Attempts to obtain the lock and
returns immediately. Returns true if
the lock was granted.

so the thread yield control until the lock is granted.

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

(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 :slight_smile:

You could install a signal handler that would unlock the Mutex, but I’m
not sure how much work would be involved to make it always do the right
thing, as you need to know that you locked it and not some other
client (this may or may not be a problem)

this is not possible for the reasons you mention.

Why are you getting the sigabrt, anyway?

because i am doing a ‘ctrl-c’ from the client tty. i am trying to make my
class super bomber. with this exception - it seems to be.

in general, i am trying to learn what happens in a drb server when a client
aborts or is otherwise terminated prematurely (eg. before the method has
finished completing)

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.).

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 :slight_smile:

···

ahoward (ahoward@fsl.noaa.gov) wrote:

On Sat, 8 Feb 2003, Eric Hodel wrote:


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

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 :slight_smile:

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 :slight_smile:

well - anyone else? :wink:

-a

···

On Sat, 8 Feb 2003, Eric Hodel wrote:

–=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
====================================

ah-ha! You really want #synchronize, it does the waiting for you, and
its not a busy-wait.

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?

Yes, the devil in the details :slight_smile:

(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 :slight_smile:

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)

/me makes a mental sticky-note

···

ahoward (ahoward@fsl.noaa.gov) wrote:

On Sat, 8 Feb 2003, Eric Hodel wrote:


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Might not be completely pertinent, but have you seen
http://www.rubygarden.org/ruby?ObjectPoolingAndThreading ?

I think it can be made to work the way you want and it doesn’t use
busy-wait.

···

On Sat, Feb 08, 2003 at 02:57:35AM +0900, ahoward wrote:

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?


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

And Bruce is effectively building BruceIX
– Alan Cox