Help With Threading
Help With Threading
- Subject: Help With Threading
- From: Kenneth Ramey <email@hidden>
- Date: Sun, 15 Mar 2009 18:20:15 -0700
Hello;
I have an application I wrote to read from a very simple GPS device
that attaches as a serial device through a USB port. I had some
success with it but it was running too slowly, since GPS fixes are
normally updated once per second. Attempting to speed the application
up, I tried several techniques including firing a timer every second
to initiate GPS reads. That caused other problems with variable
usage, possibly because I wasn't getting through the record decode
subroutine before time for the next fix to be read.
I tried rewriting the code so that the main loop was an infinite loop
that constantly read records and decoded them as quickly as possible.
When I ran that, the user interface locked up and no mouse or keyboard
events were recognized but the GPS was read very quickly. Even adding
sleep() calls to the main loop didn't alleviate the situation.
My next attempt was to implement a client/server architecture using
threads. At first, I tried creating a secondary thread within my
application and used it for the GPS I/O. But, when I terminated the
main program, the secondary thread kept running and caused errors
because the serial port was closed by the main application.
Next, I read Apple's "Threaded Programming Guide" and looked at the
samples labelled "TrivialThreads" and "SimpleThreads". I was using
them as a template but couldn't understand how the secondary thread
was cleanly terminated or deallocated. Rereading the "Readme" files
with the two samples, I noticed that they both state that they don't
cleanly handle thread termination.
Can anyone point me at some better documentation on thread programming
in OSX? My application needs to read and decode between 6 and 8 GPS
records per second while still remaining responsive to the user
interface. Threads seem to me to be the obvious solution but I'm not
having much luck finding relevant information.
Thanks for any help anyone can provide.
-------------------------------
Ken Ramey
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden