dispatch_async block on main queue is never execeuted

前端 未结 3 1331
一整个雨季
一整个雨季 2021-02-12 23:12

I have an app that uses a connection queue that handles the connections on a background thread. Each connection sends a JSON post, then when it receives a success, saves some o

3条回答
  •  你的背包
    2021-02-13 00:12

    I believe this is a great discussion. I came across this when I had the following code:

       dispatch_synch(dispatch_get_main_queue()){
            print("I am here")
       }
    

    the print code did not execute as I was dispatching a 'synch' block on the serial main thread which caused a dead lock. print was waiting for the dispatch to finish and dispatch was waiting for print to finish. When you dispatch in the main serial queue then you should use dispatch_async. and i guess if you use a concurrent queue then dispatch synch suits better

提交回复
热议问题