Is it possible to use GCD without blocks? Is there a way to use GCD using _f variant as mikeash says in his post. I searched around and there is no proof for either sides. is it possible or impossible.
If its doable please give an example.
/Selvin
Is it possible to use GCD without blocks? Is there a way to use GCD using _f variant as mikeash says in his post. I searched around and there is no proof for either sides. is it possible or impossible.
If its doable please give an example.
/Selvin
Yes you can, as stated on the article:
You can use GCD without blocks, via the _f variants provided for every GCD function that takes a block
If you look at the GCD documentation you can check the variants. If you need a quick example there are many on SO:
Of course it is possible! By
_f
variants Mike just mean set ofGCD
functions with_f
suffix. They are alternatives for usualGCD
functions but can accept a user defined function as a parameter instead of blocks. There are plenty of them:They accept
dispatch_function_t
parameter (instead of usualdispatch_block_t
) which is defined as follows:typedef void (*dispatch_function_t)(void*)
.As you see it can accept any user parameter and also a function because of
*void
pointer. So you can even usedispatch_function_t
with function that have no arguments - you can just write a wrapper function like so:Or pass a function pointer as a parameter. Or on the contrary you can use
_f
variants of GCD functions with user defined functions which can accept any number of arguments via the varargs (variadic functions) - just write a function wrapper for it also as above. As you see_f
functions is rather a powerful mechanism and you are not limited only with blocks without parameters for GCD but can use usual functions.