Is NSNotificationCenter thread-safe?

rharder

Do not read this sign.
Is the default NSNotificationCenter thread-safe? That is, if I have a separate thread that posts a notification when it's done to [NSNotificationCenter defaultCenter], will I wreak havoc with my application?

I created a ThreadWorker class inspired by Java's SwingWorker class. It lets you run tasks in another thread, but then it notifies the NSNotificationCenter upon completion.

-Rob
 
But there's more.

Although NSNotificationCenter is thread-safe, the notifications it posts are not in the main event-dispatching thread.

Does anyone have an idea about how to place a notification or have a selector called from the main thread?

This is particularly important when the end result of some long thread's work is modifying some GUI component which are all not thread-safe.

-Rob
 
Back
Top