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 6966385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:11:05+00:00 2026-05-27T16:11:05+00:00

say i have a process which spawns 2 threads the first thread listens in

  • 0

say i have a process which spawns 2 threads

the first thread listens in a tight loop for packet events on a UDP port.
the second thread is to receive the bytes contained in this UDP packet and parse it/do stuff.

can anyone recommend a faster method than using linux message queues?
i think they are slow because they are copying the bytes upon writing to the queue and copying them again upon reading from the queue

i am aware of the zeromq library but is there a slick way to do this without that overhead?
i realize i could just use a tcp/ip socket between the two threads for simple queued communication but is there a faster way?

i am thinking maybe a ring buffer in memory that is shared between the threads and a mutex used to control a pointer to the most recently updated element?

anyones thoughts here?

  • 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-27T16:11:06+00:00Added an answer on May 27, 2026 at 4:11 pm

    The most efficient method that I can think of would use one linked list, one mutex, and one condition variable:

    • Thread A:

      1. Allocate a udp-packet-buffer object (the object should contain previous and next pointers, and an array of bytes to store UDP data in)
      2. recv() UDP data into the object’s byte-array
      3. lock the mutex
      4. append the udp-packet-buffer object to tail of the linked-list
      5. unlock the mutex
      6. signal the condition variable
      7. goto 1
    • Thread B:

      1. wait on the condition variable (until the condition variable is signaled)
      2. lock the mutex
      3. pop the next udp-packet-buffer off the head of the linked-list
      4. unlock the mutex
      5. parse/handle the UDP data in the udp-packet-buffer object
      6. delete the udp-packet-buffer object
      7. goto 1

    That gives you a zero-copy communications mechanism. The time spent holding the mutex is minimal, so contention should be low also.

    If you wanted to optimize a bit further, you could have thread B grab all of the items out of the linked-list at once instead of just popping off one at a time — something that is possible to do in O(1) time with a linked list. And then have thread A signal the condition variable only if the linked list was empty just before it appended its latest udp-packet-buffer object. That would cut down on the number of times the threads have to lock/unlock/signal when under heavy load.

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

Sidebar

Related Questions

In my application, I have a process which forks off a child, say child1,
Say I have a data file that I want to process; I want to
Say I have two process p1,p2 runnning as a part of my application. Say
Let's say I have a list somewhere called majorPowers which contain these two lists:
Hi I am trying to do the following: I have a process which can
I have a form, I submit_form_ok the form codes to /process which returns a
Say I have a large working directory and I am in the process of
Say I have a web project which uses a WCF service for behind-the-scenes processing,
I have a File which process many other files and may take upto 30mins
I have a process users must go through on my site which can take

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.