Status report! TGS 2009
Aug 09

So as part of my ongoing iPhone project/learning experience, I’ve been dabbling with threads. Threads are one of things that I’ve known about in programming for a while now, but always had this irrational fear of, and avoided like the plague.

Still, this project required it (the alternative is having the user spend almost half their time waiting for the program - not cool), and so I’ve been doing a lot of reading, and playing with different ways of implementing them.

My fear now seems a lot more rational.

To start off with, Apple’s threaded programming guide, whilst incredibly informative, is written with some strange incantation woven into its text, one that has the power to reduce a grown man to tears. Whilst it’s easy to write this off as a lack of understanding on my part, at least I’m not the only one.

But I’m also finding that, mentally, there’s a muscle here that is totally underdeveloped. Normally I’d say I’m pretty good at mentally picturing the sequence of method calls and so forth, but for more than a single thread at a time, my head explodes (asplodes?). Coupled with some of my less-than-model debugging practices, today has been a fun day.

To derive some entertainment from this process, I thought I’d illustrate my latest and greatest problem, in humorous form.

Thread A: Hmm, I need to get some info. Luckily my buddy over here went and grabbed all the relevant stuff beforehand. Oh wait, he’s still getting it, I’ll just sit here and wait for him to get it ready.
Thread B: Urgh, why am I the one who has to do all the heavy lifting? Anyways, this lot of stuff is just about done. Hey A! I need you to grab this for me, it’s pretty much ready.
Thread A: I’d love to help man, but I’m waiting for that stuff to be ready.
Thread B: You just need to take it, then it’ll be ready! Just take it already!
Thread A: No no no, I’m waiting. Seriously, I can’t do anything until it’s ready.
Thread B: But it won’t be ready until you take it. GOD, YOU ALWAYS DO THIS!

It really is quite a simple problem, but it’s taking me far longer to get it clear than I’d like. Still, it does make the eventual problem solving all the more rewarding.

It has also got me looking at alternate ways to do things. I’m not sure that my current approach is exactly the most optimal one, so all of this could ultimately prove somewhat redundant. Still, it’s been (somewhat) fun!

written by .klik2


One Response to ““Oh what a tangled web we weave””

  1. 1. Chi-Sze Says:

    Are you sure that it didn’t implode? O_o

    Also, why don’t you post your problem and sample code to a forum specialising in this? They might be able to point you in the right direction :)

Leave a Reply