* Objective-C Objects and Locking
@ 2004-07-06 19:17 John Richard Moser
0 siblings, 0 replies; only message in thread
From: John Richard Moser @ 2004-07-06 19:17 UTC (permalink / raw)
To: linux-c-programming, linux-gcc
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I'm writing up my own objective-c framework, something to use in place
of OpenStep/Cocoa/etc. So, I'm in complete control of what happens with
my base object, SVObject (which ironically inherits from Object :).
I'm attempting to implement a swizzling subsystem which allows any
SVObject inheriting object to dynamicly handle swizzle requests safely
and effectively. Because I want to work in a threaded environment, I
need to lock properly.
What I'm thinking is to use a mutex lock around all members that may not
run during a swizzle and deflect in-swizzle calls to the new swizzle
master. The current logic I'm pondering is:
- -(void) someMemberThatIsAffected {
~ if ([my_swizzle_lock tryReadLock]) { /*Can we lock?*/
~ /*
~ * We couldn't lock, so we wait for the swizzle lock to become
~ * unlocked, then send the message to whatever swizzled us.
~ */
~ [my_swizzle_lock readLock];
~ [my_swizzle_master someMemberThatIsAffected];
~ }
~ else { /*Or we just complete*/
~ ...
~ }
~ [my_swizzle_lock unlock];
}
A swizzle would -writeLock my_swizzle_lock, so this would detect the lock.
Here's the issue I have: Looking at this logic, if the entire swizzle
is done between the actual message passing call and the -tryReadLock,
which is quite plausible in an SMP situation, this will fail to detect.
~ Also, the new object may want to pass messages down to this object, so
I can't just feed all messages upwards.
I don't want to abandon the idea of supplying simplistic swizzling;
however, I would have to detect in-progress swizzles reliably. I can't
think of anything to atomicize, and don't know how to make chunks of
code atomic anyway.
Any thoughts?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFA6vrZhDd4aOud5P8RAqioAKCOswm5y2OM0ShzROOXvR5R2BEC6QCfW6hQ
Sf/+aJXpdPUkBDsmq3zcJig=
=PyRP
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-07-06 19:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-06 19:17 Objective-C Objects and Locking John Richard Moser
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).