Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 30, 2013, 01:00 AM   #1
multinode
macrumors regular
 
Join Date: Feb 2011
Critical section coding with OSX 10.6

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?
__________________
PLEASE DON'T SUPPORT ANTI AMERICA WIKILEAKS ... CUTE BUT DESTRUCTIVE

Last edited by multinode; Aug 30, 2013 at 01:26 AM.
multinode is offline   0 Reply With Quote
Old Aug 30, 2013, 03:02 AM   #2
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by multinode View Post
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.
gnasher729 is offline   0 Reply With Quote
Old Aug 30, 2013, 10:35 AM   #3
multinode
Thread Starter
macrumors regular
 
Join Date: Feb 2011
Quote:
Originally Posted by gnasher729 View Post
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.
__________________
PLEASE DON'T SUPPORT ANTI AMERICA WIKILEAKS ... CUTE BUT DESTRUCTIVE
multinode is offline   0 Reply With Quote
Old Aug 30, 2013, 10:59 AM   #4
multinode
Thread Starter
macrumors regular
 
Join Date: Feb 2011
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?
__________________
PLEASE DON'T SUPPORT ANTI AMERICA WIKILEAKS ... CUTE BUT DESTRUCTIVE
multinode is offline   0 Reply With Quote
Old Aug 30, 2013, 11:35 AM   #5
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
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
robbieduncan is offline   0 Reply With Quote
Old Aug 30, 2013, 11:50 AM   #6
multinode
Thread Starter
macrumors regular
 
Join Date: Feb 2011
Quote:
Originally Posted by robbieduncan View Post
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.
__________________
PLEASE DON'T SUPPORT ANTI AMERICA WIKILEAKS ... CUTE BUT DESTRUCTIVE
multinode is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:35 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC