Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

multinode

macrumors regular
Original poster
Feb 4, 2011
150
0
I have N SDCards connected to my MacBook via USB. This is an OSX 10.6 MacBook business app with as many as N customers randomly inserting SDCards. My app recognizes each insertion with a Disk Arbitration DiskAppearedCallback and that callback processes the information in a file on the card and determines the USB locationID to identify which customer did the mount.

My question is how to have the multiple callbacks be processed SEQUENTIALLY, i.e. I don't want any callback to be interrupted by another mount callback. I think that this is a critical section problem ... locks, semaphores, etc.

Does anybody here have any suggestions?
 
Last edited:

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
I have N SDCards connected to my MacBook via USB. This is an OSX 10.6 MacBook business app with as many as N customers randomly inserting SDCards. My app recognizes each insertion with a Disk Arbitration DiskAppearedCallback and that callback processes the information in a file on the card and determines the USB locationID to identify which customer did the mount.

My question is how to have the multiple callbacks be processed SEQUENTIALLY, i.e. I don't want any callback to be interrupted by another mount callback. I think that this is a critical section problem ... locks, semaphores, etc.

Does anybody here have any suggestions?

Enter the debugger. Set a breakpoint on the callback. Is it called on the main thread or on a background thread? Better yet, check the documentation. What does it say? Main thread is single threaded.
 

multinode

macrumors regular
Original poster
Feb 4, 2011
150
0
Enter the debugger. Set a breakpoint on the callback. Is it called on the main thread or on a background thread? Better yet, check the documentation. What does it say? Main thread is single threaded.

Thanks GNASHER. I'm not certain that this is a multithreading issue??? I usually think of multithreading as the processor giving each thread a quantum of time one after the other. In my case, I'm thinking that ONE thread is doing all the mount processing, BUT while one mount callback is executing the callback code block, another mount callback cannot interrupt to enter that same code block. I think this is a matter of locking the code block to prevent non lock holders from entering.

I don't understand your statement "main thread is single threaded" ... please elaborate. Your statement seems to imply that a DA notification spawns a new thread and that execution in the main thread doesn't allow that. If that is what you mean, then that begs the question of how any DA notification can execute. Again, I'm not sure that my issue is about multi threading.
 

multinode

macrumors regular
Original poster
Feb 4, 2011
150
0
Hello GNASHER ...

I have an idea ... maybe I do want multiple threads. Maybe each time a DA Disk Appears notification happens the callback should explicitly spawn a new thread and then call the actual mount processing code to execute in the new (child) thread (HOW?). The beginning of the actual mount processing code could spin on a lock which would get released whenever a player completes/exits the execution of the mount processing code.

Does this make sense? Did you understand me?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Sounds like a job for Grand Central Dispatch. If you want to ensure that the dispatched events (mounts) are handled one at a time in the order they happened dispatch against your own queue that you create with
Code:
DISPATCH_QUEUE_SERIAL
 

multinode

macrumors regular
Original poster
Feb 4, 2011
150
0
Sounds like a job for Grand Central Dispatch. If you want to ensure that the dispatched events (mounts) are handled one at a time in the order they happened dispatch against your own queue that you create with
Code:
DISPATCH_QUEUE_SERIAL

Yeah ... I was thinking about queues and GCD too. In other words, the DA callback should go to some intermediate code ... queues, locks, etc. ... which would then go to the actual mount processing code.

Thanx.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.