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

  • SEARCH
  • Home
  • 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 8406491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:07:28+00:00 2026-06-09T23:07:28+00:00

How would one go about creating a queue that can hold an array, more

  • 0

How would one go about creating a queue that can hold an array, more over an array with variable amounts of rows.

char data[n][2][50];
//Could be any non 0 n e.g:
n=1; data = {{"status","ok}};
// or
n=3; {{"lat", "180.00"},{"long","90.123"},{"status","ok}};
// and so on

n to be added to the queue. Or is there even a better solution than what I’m asking? A queue is easy enough to write (or find re-usable examples of) for single data items but I’m not sure what method I would use for the above. Maybe a struct? That would solve for array and n…but would it solve for variable array?

More broadly the problem I’m trying to solved is this.
I need to communicate with a web server using POST. I have the code for this already written however I don’t want to keep the main thread busy every time this task needs doing, especially since I need to make other checks such as is the connection up, if it isn’t I need to back off and wait or try and bring it back online.

My idea was to have a single separate dedicated to this task. I figured creating a queue would be the best way for the main thread to let the child thread know what to do.

The data will be a variable number of string pairs. like:

Main

//Currently does
  char data[MAX_MESSAGES_PER_POST][2][50];
  ...
  assembles array
  sendFunction(ptrToArray, n);
  resumes execution with large and un predicatable delay

//Hopefully will do
  ...
  queue(what needs doing)
  carry on executing with (almost) no delay

Child

while(0)
{
  if(allOtherConditionsMet())  //Device online and so forth
  {
    if(!empty(myQueue))
    {
       //Do work and deque
   }
 }
 else
 {
     //Try and make condition ok. Like reconect dongle.
 }
  // sleep/Back off for a while
}
  • 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-06-09T23:07:29+00:00Added an answer on June 9, 2026 at 11:07 pm

    You could use an existing library, like Glib. GLib is cross platform. If you used GLib’s asynchronous queues, you’d do something like:

    The first thread to create the queue executes:

    GAsyncQueue *q = g_async_queue_new ();
    

    Other threads can reference (show intent to use the queue) with:

    g_async_queue_ref (q);
    

    After this, any thread can ‘push’ items to the queue with:

    struct queue_item i;
    g_async_queue_push (q, ( (gpointer) (&i)));
    

    And any thread can ‘pop’ items from the queue with:

    struct queue_item *d = g_async_queue_pop (q);
    /* Blocks until item is available.  */
    

    Once a thread finishes using the queue and doesn’t care any more about it, it calls:

    g_async_queue_unref (q);
    

    Even the thread which created the queue needs to do this.

    There are a bunch of other useful functions, which you can all read about on the page documenting them. Synchronization (locking/consistency/atomicity of operations) is taken care of by the library itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would one go about creating an ipad app that has a similar view
How would one go about creating a function file that is stored outside of
How would one go about creating a plugin or something of the like that
How would one go about creating a custom action in Cocos2D that was able
I've been mulling over how one would go about creating a P2P system (like
How would one go about creating a custom protocol? I know you can create
How would I go about creating more than one OnClickListener for one Button .
How would one go about proving to management that a batch reformat of all
How would one go about writing a query that selects items 2000-2010 out of
Where would I go about placing partial files shared by more than one model?

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.