I'm trying to debug a multi-threaded PKCS11 application that I'm working on. So far the functionality is almost working but I'm having a really strange problem.
The program has two threads: one that gets spawned after initialization that just sits and waits for events, like the token being inserted or removed. It uses C_WaitForSlotEvent to do this. The other thread is the main execution thread. The thing that is happening is that the looping thread seems to be working just fine, but the main thread gets stuck inside SCardGetStatusChange (pcsclite library, source file: winscard_clnt.c on line 1033) trying to lock a mutex. Here's where it gets weird: The looping thread is continually locking and unlocking this same mutex as it runs its various function calls, but for some reason the main thread is never given the lock, as if the scheduler is being completely unfair or something. As far as I know, both threads have the same priority (I have done nothing to change them). Here is some debug output from the program execution: (There is lots of output before this. At this point, just the main thread is running.) Thread = 4143896416 - Mutex = 9f653d0 - SYS_MutexLock (main thread locks mutex) Thread = 4143896416, SCardGetStatusChange 1.2 Thread = 4143896416, SCardGetStatusChange 3 Thread = 4143896416, SCardGetStatusChange 4 Thread = 4143896416, SCardGetStatusChange 5 Thread = 4143896416, SCardGetStatusChange 6 Thread = 4143896416, SCardGetStatusChange 7 Thread = 4143896416, SCardGetStatusChange 8 Thread = 4143896416, SCardGetStatusChange 9 Thread = 4143896416, SCardGetStatusChange 10 Thread = 4143896416, SCardGetStatusChange 11 Thread = 4143896416, SCardGetStatusChange 12 Thread = 4143896416, SCardGetStatusChange 13 Thread = 4143896416 - Mutex = 9f653d0 - SYS_MutexUnLock (main thread unlocks it) Thread = 4143896416, SCardGetStatusChange 14 Thread = 4143819696 - LOOPING THREAD STARTS UP AND DOES SOME STUFF Thread = 4143819696 - Mutex = bfe800 - SYS_MutexLock Thread = 4143819696 - Mutex = bfe800 - SYS_MutexUnLock Thread = 4143819696, MSCWaitForTokenEvent 4 Thread = 4143819696, SCardGetStatusChange 1 Thread = 4143819696 - Mutex = be9408 - SYS_MutexLock Thread = 4143819696 - Mutex = be9408 - SYS_MutexUnLock Thread = 4143819696, SCardGetStatusChange 1.1 Thread = 4143819696 - Mutex = 9f653d0 - SYS_MutexLock (looping thread obtains lock) Thread = 4143819696, SCardGetStatusChange 1.2 Thread = 4143819696, SCardGetStatusChange 3 Thread = 4143819696, SCardGetStatusChange 4 Thread = 4143819696, SCardGetStatusChange 5 Thread = 4143819696, SCardGetStatusChange 6 Thread = 4143819696, SCardGetStatusChange 7 Thread = 4143819696, SCardGetStatusChange 8 Thread = 4143819696, SCardGetStatusChange 9 Thread = 4143896416 - Mutex = bfe800 - SYS_MutexLock (MAIN THREAD AGAIN) Thread = 4143896416 - Mutex = bfe800 - SYS_MutexUnLock Thread = 4143896416, MSCWaitForTokenEvent 4 Thread = 4143896416, SCardGetStatusChange 1 Thread = 4143896416 - Mutex = be9408 - SYS_MutexLock Thread = 4143896416 - Mutex = be9408 - SYS_MutexUnLock Thread = 4143896416, SCardGetStatusChange 1.1 Thread = 4143896416 - Mutex = 9f653d0 - SYS_MutexLock (main thread tries to obtain lock. This is the last time we see main thread doing anything. It gets stuck here.) Thread = 4143819696, SCardGetStatusChange 10 (LOOPING THREAD RESUMES) Thread = 4143819696, SCardGetStatusChange 11 Thread = 4143819696, SCardGetStatusChange 12 Thread = 4143819696, SCardGetStatusChange 13 Thread = 4143819696 - Mutex = 9f653d0 - SYS_MutexUnLock (looping thread unlocks, yet main thread never gets the lock) Thread = 4143819696, SCardGetStatusChange 14 Thread = 4143819696, MSCWaitForTokenEvent 5 Thread = 4143819696, SCardGetStatusChange 1 Thread = 4143819696 - Mutex = be9408 - SYS_MutexLock Thread = 4143819696 - Mutex = be9408 - SYS_MutexUnLock Thread = 4143819696, SCardGetStatusChange 1.1 Thread = 4143819696 - Mutex = 9f653d0 - SYS_MutexLock (looping thread locks again. This keeps going on forever.) Thread = 4143819696, SCardGetStatusChange 1.2 Thread = 4143819696, SCardGetStatusChange 3 Thread = 4143819696, SCardGetStatusChange 4 Thread = 4143819696, SCardGetStatusChange 5 Thread = 4143819696, SCardGetStatusChange 6 Thread = 4143819696, SCardGetStatusChange 7 Thread = 4143819696, SCardGetStatusChange 8 Thread = 4143819696, SCardGetStatusChange 9 Thread = 4143819696, SCardGetStatusChange 10 ... (lots more output follows) Anyone have any ideas? I have no idea why this isn't working. It's like the scheduler is being unfair or something. Thanks, Carl Youngblood _______________________________________________ Muscle mailing list [EMAIL PROTECTED] http://lists.drizzle.com/mailman/listinfo/muscle
