multithreading - wait for other thread to finish in objective c -


i using mgtwitterengine fetch tweets twitter. uses asynchrounous paradigm fetch tweetsin thread. returns fetched results main thread.

because have processing todo after tweets fetched, introduce thread prevent locking ui thread. lik way: ui thread starts new thread x. thread x starts asynchronous fetching of tweets mgtengine, , waits finish. when mgtwitterengine returns, thread x processes tweets, , notifies ui thread ready.

my question is: how set thread x wait till mgtwitterengine reade?

there little excuses not use multithreading blocks now. quicker develop nsoperations, synchronisation simpler, jumping threads (e.g. grabbing ui thread) simpler , in own experience performance better.

in case, create block, spawn new thread fire async fetch (possibly spawning async fetch each one- makes cancelations easier) put 2 sync blocks in queue fire after fetches done processing , ui update. here tut: http://www.fieryrobot.com/blog/2010/06/27/a-simple-job-queue-with-grand-central-dispatch/

//goes in tweet delegate  myqueue = dispatch_queue_create("myqueue", 0);//local instance var dispatch_queue_t  dispatch_async(myqueue, ^{                        [self processtweets];//executed after fetch done.                       dispatch_sync(dispatch_get_main_queue(), ^{                           [self uibasedfunction];//executed on main thread                                                             });                          }); dispatch_release(myqueue); 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -