[libdispatch-dev] trivial linux patch + general questions

Dave Zarzycki zarzycki at apple.com
Fri Apr 22 08:25:30 PDT 2011


C. Bergström,

dispatch_sync() against a global concurrent queue is meaningless. They're always concurrent. Please consider using dispatch_apply*() for this kind of problem. You'll find that the fit is quite natural and more efficient. :-)

davez


On Apr 22, 2011, at 5:46 AM, C. Bergström wrote:

> Joakim Johansson wrote:
>> Any results/experience would be of interest, both good or bad!
>>  
> 
> Here's the problem we're currently facing..
> 
> The following code and some details from another engineer:
> 
>   dispatch_queue_t q = dispatch_get_global_queue(0, 0);
>   int iterations = n / m;
>   struct args1 args[iterations];
>   for (int i=0 ; i<iterations ; i+=m)
>   {
>       args[i].n = &n;
>       args[i].v1 = &v1;
>       args[i].v2 = &v2;
>       args[i].v3 = &v3;
>       args[i].start = i*m;
>       args[i].start = args[i].start + m;
>       dispatch_async_f(q, &args[i], codeletOk_codelet1);
>   }
>   struct args1 last = { &n, &v1, &v2, &v3, iterations*m, n%m };
>   dispatch_sync_f(q, &last, codeletOk_codelet1);
> #1 in this statement for (int i=0 ; i<iterations ; i+=m) . Should it be like for (int i=0 ; i<iterations * m ; i+=m) for an complete loop?
> #2 args[i].start = i*m;
>   args[i].start = args[i].start + m;
> should it be like:
>   args[i].start = i;
>   args[i].start = args[i].start + m;
> #3  struct args1 last = { &n, &v1, &v2, &v3, iterations*m, n%m }; Should it be like:
>     struct args1 last = { &n, &v1, &v2, &v3, iterations*m, n%m + iterations*m} ?
> #4 When I run the the code I found it wouldn't wait until dispatch_async_f(q, &args[i], codeletOk_codelet1) is over then the whole program was over.
> 
> 
> It can run correctly if we replace dispatch_async_f(q, &args[i], codeletOk_codelet1); with codeletOk_codelet1(&args[i]) and dispatch_sync_f(q, &last, codeletOk_codelet1); with codeletOk_codelet1(&last).
> ------
> Any tips on how to debug the difference between async and sync?
> 
> Thanks
> 
> ./C
> 
> _______________________________________________
> libdispatch-dev mailing list
> libdispatch-dev at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/libdispatch-dev



More information about the libdispatch-dev mailing list