[libdispatch-dev] trivial linux patch + general questions

"C. Bergström" cbergstrom at pathscale.com
Fri Apr 22 05:46:04 PDT 2011

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 
Any tips on how to debug the difference between async and sync?



More information about the libdispatch-dev mailing list