At 4:01 PM +0100 7/2/03, Alan Burlison wrote:
Dan Sugalski wrote:

Unfortunately given what the code does we can't use mutexes, since they're not interrupt-safe, which I'm not particularly happy about. The queues in question are thread-specific, though, which takes some of the danger out of things. I fully expect to have to do more work than just disabling optimizations to disable reordering to make this function right everywhere. (I know, I know, platform-independent interrupt code is just not doable, but...)

Hmm, I don't think the issue is that mutexes aren't interrupt-safe, I think the issue is that if an interrupt routine is reentered it may already be holding a mutex and therefore self-deadlock.

I'm pretty sure the POSIX docs say that you can't call mutex routines from within interrupt code, which makes sense--the last thing you want is for an interrupt handler to block on a mutex aquisition.


This isn't actually a big deal, as it's reasonably straightforward to write code that can handle multiple user-space readers and writers (which can guard themselves with mutexes) and a single interrupt-time writer. Proper ordering and checking of operations inside the code makes this straightforward, if a pain. (And I know the ordering's doable, otherwise every single OS on the planet with interrupt code would fall down and go boom :) The nasty part comes in with multiple interrupt-time writers. I'm not sure if it's common to be able to have multiple concurrent interrupt handlers running, but I do know it's possible.

I'd considered just up and disabling interrupts entirely but I didn't want to take the performance hit from it. I'm thinking now that decision was a bad one, but luckily one that's not welded into anything anywhere (and wouldn't have been even if I'd kept going this way, as all we would've guaranteed is thread-safe interrupt-safe queues) so it's simple enough to change.

Disabling signals and interrupts is still going to be platform-specific, but that's not a big deal.
--
Dan


--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to