On Fri, Feb 12, 2010 at 04:45:37PM -0600, Shawn Walker wrote: > On 02/12/10 04:41 PM, John Rice wrote: > >Shawn is this an API bug? When the api throws an exception such as > >ImageLockedError I would expect any subsequent call to > >api.can_be_canceled to return False. > > > >We have logic on exit to kick off an api.cancel() in a separate thread > >if api.can_be_canceled returns true. The thread never returns after an > >ImageLockedError has been thrown previously and so PM doesn't exit > >cleanly. We worked around it in the installer but I missed this in PM > >itself. > > The short answer is, maybe, maybe not. In a multi-threaded program > you could have had an operation already in progress at the time > another operation failed with an ImageLockedError. The operation > that's actually in progress itself could be cancelable. > > It's conceivable that in a race condition scenario, you could end up > with a sequence like this: > > 1) Start_OP_A > 2) Start_OP_B > 3) OP_B_FAILS; can_be_canceled_TRUE > 4) OP_A_Finishes > 5) ... ? > > It's also possible that an operation isn't setting can_be_canceled > to False when it's failing or completing. It's hard to say without > being able to consistently reproduce the issue and then trying to > find analyse the state at the point of unexpected failure.
Let me put an even finer point on this. Since it's possible that multiple threads are trying to start different operations at the same time, all operations that wish to be cancelable must hold the activity lock for the duration of their operation. This prevents Operation B from fiddling with the can_be_canceled state while Operation A is still in progress. The cancel lock is used to serialize threads waiting for an operation to be canceled. Waiters block on the cancel_cv. Canceled operations signal this to wake up sleeping threads. For these operations the lock order is: 1. activity lock 2. cancel lock If Operation B is running and fails to get the activity lock because Operation A is in progress, then Operation B _must_ not affect the state of can_be_canceled. In this case, can_be_canceled only refers to Operation A -- the owner of the activity lock. -j _______________________________________________ pkg-discuss mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
