Safely Destroying Notification From IOServiceAddMatchingNotification
Safely Destroying Notification From IOServiceAddMatchingNotification
- Subject: Safely Destroying Notification From IOServiceAddMatchingNotification
- From: Chris Suter <email@hidden>
- Date: Thu, 09 May 2013 13:57:04 +1000
Hi all,
I'm using IOServiceAddMatchingNotification and I’m just wondering how to safely destroy the notification. I had a quick look at the source code and it looks like you cannot be sure that the callback won't be called after calling IOObjectRelease if the notification takes place on a different thread. Admittedly, the window is pretty small, but it's a window nonetheless.
The solution I currently have is to change my callback to:
static void callback (void *param, io_iterator_t notification)
{
@synchronized (param) {
if (IOObjectGetUserRetainCount (notification) < 2)
return;
// Now safe to use param...
}
}
and where I destroy the notification:
@synchronized (param) {
IOObjectRelease (notification);
}
Just wondering if this is a known issue and whether this is the recommended approach. If so, I think it ought to be documented somewhere, or better still, should be fixed in IOKitLib so this kludge isn't necessary.
Regards,
Chris
<rdar://problem/13845851>
p.s. Please dupe if this affects your code and you'd like to see this fixed.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden