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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:59:42+00:00 2026-06-04T06:59:42+00:00

I have two threads (I am using pthreads on GNU/Linux). Now they are sharing

  • 0

I have two threads (I am using pthreads on GNU/Linux). Now they are sharing information using global variables (I know, it’s not nice). At the end of each cycle they have to send the value of 5 variables (doubles) to the other thread.
I would like to introduce a fixed time delay in their communication channel,

i.e.

thread1 (1kHz) <—> 10ms <—> thread2 (1kHz)

I was thinking that, at each cycle, I could create a thread which reads the value, sleep for 10ms, then forward it to the other thread and then dies.
This will make the system create 2 threads every cycle, one for each direction of the communication channel (2 threads per millisecond).

Is there any other intelligent way of simulating a delay in the communication?

UPDATE: I do not want to synchronize the communication of the threads but add a delay between them.
If thread1 writes something at time 1s the other thread should be able to read it only at time 1s + 10ms.

  • 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-04T06:59:42+00:00Added an answer on June 4, 2026 at 6:59 am

    This doesn’t sound like a performance problem, so make it simple. No need for complex data structures, extra threads, etc.

    Make a struct for your data, add a timestamp field to it.

    Make an array to hold at least 10 of your structs. Go for 100 to be safe. Not going to use a lot of memory here, so who cares. Heck you could malloc it whenever it needed to grow.

    Each thread has one such array, and a count of items in the array.

    When a thread is ready to send data, do two things:

    1. Check the timestamp of the first item in it’s array, and if old
      enough send that data to the other thread. After sending, decrement
      the count and memmove the rest of the items in the array down one
      notch.
    2. Add the current/new data to the end of the array with the
      current time stamp and increment the count.

    Repeat for other thread.

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

Sidebar

Related Questions

i have two threads, they run pretty fast, i'm using pthread_mutex_lock and pthread_mutex_unlock to
I am using pthread library under Linux for creating threads and I have two
There is scenario, I have two threads both are using same mutex. One thread
I have a List and two threads that using the List. The first thread
I have the following Windows code that spawns two threads then waits until they
I have two threads that need to send TCP messages using the same already
I have two threads that need to send TCP messages using the same already
(I am using Java!) I have two threads t1 and t2. Each thread reads
I have two threads that use an event for synchronization. In each thread they
I'm not able to synchronize two threads using a set: private Set<String> set; ...

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.