Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6896603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:03:52+00:00 2026-05-27T07:03:52+00:00

In the GCD documentation it’s quite clear that to submit work to the main

  • 0

In the GCD documentation it’s quite clear that to submit work to the main queue, you need to either be working within an NSApplication (or UIApplication) or call dispatch_main() to act as a run loop of sorts. However, do I need to do anything to set up the global concurrent queue?

Basically what I am asking is: If I write a plain simple C program, do I need to perform any special setup before I go dispatch_get_global_queue() and start giving it work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:03:52+00:00Added an answer on May 27, 2026 at 7:03 am

    No, you don’t need any additional setup. But you need to call dispatch_main() to start the GCD dispatcher.
    As dispatch_main() never returns, this will also prevent your main function from reaching it’s return.

    Example for a minimal C program that uses GCD & a global queue (based on http://wiki.freebsd.org/GCD):

    #include <dispatch/dispatch.h>
    #include <err.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
        dispatch_queue_t globalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
        dispatch_time_t dispatchTime = dispatch_time(DISPATCH_TIME_NOW, 5LL * NSEC_PER_SEC);
        dispatch_after(dispatchTime, globalQueue, ^{
            printf("Dispatched on global queue\n");
            exit(0);
        });
        dispatch_main();
        return (0);
    }
    

    To compile this, use:

    clang -Wall -Werror -fblocks -L/usr/local/lib -I/usr/local/include -o test test.c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does GCD assure that all the blocks working in the same queue are always
I keep getting that error. Here's the code (it's for GCD): Euc := proc
In GCD, is there a way to tell if the current queue is concurrent
In short: Given that a is coprime to b if GCD(a,b) = 1 (where
Can you suspend a GCD timer from a queue besides the one it's schedule
I have some simple doubts about NSOperation and GCD that I have not found
I have an iPad application with multi-threading capabilities using GCD. When i need to
I need some help in using objects from Core Data with GCD; I seem
I'm working with some code that does a bunch of asynchronous operating with various
I read that GCD synchronous queues (dispatch_sync) should be used to implement critical sections

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.