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
On
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
_fvariants Mike just mean set ofGCDfunctions with_fsuffix. They are alternatives for usualGCDfunctions but can accept a user defined function as a parameter instead of blocks. There are plenty of them:They accept
dispatch_function_tparameter (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
*voidpointer. So you can even usedispatch_function_twith 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
_fvariants 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_ffunctions is rather a powerful mechanism and you are not limited only with blocks without parameters for GCD but can use usual functions.