How to use dispatch_async_f?

The function I want to queue does not accept any parameters. What can I pass as paramContext ? Passing to NULL generates a compilation error "Invalid use of void expression." I don’t want to add a parameter to my function, just to compile it - how do I do this work?

Mac OS X Snowleopard, Xcode 3.2.6 with Objective-C

+6
source share
2 answers

You need to wrap the function somehow. The easiest way is to use dispatch_async() instead, as in

 dispatch_async(queue, ^{ myFunc() }); 
+2
source

While you can simply pass 0 / NULL for the context argument, dispatch_async_f() takes void (*)(void*) as a parameter to the function, you cannot pass it a function that takes no arguments.

You need to either change your function to accept the void* parameter:

 void func(void*) {} 

... or, if you cannot, wrap it:

 void orig(void) {} void wrapper(void*) { orig(); } // ... dispatch_async_f(queue, 0, &wrapper); 
+11
source

Source: https://habr.com/ru/post/908666/


All Articles