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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:30:31+00:00 2026-06-01T10:30:31+00:00

In my application in C++ I am using pthreads. I have a main thread

  • 0

In my application in C++ I am using pthreads. I have a main thread that parcels out work to another thread to read from disk and a third thread to write to disk. This allows the main thread to perform in real-time and not get hiccups due to disk io by the read thread keeping ahead of the main threads consumption and the write thread keeping up with the main threads production. In other words, the read thread produces data for processing by the main thread and the write thread consumes data produced by the main thread.

In my application, I have shared resources between the main thread and the read thread and I have another set of shared resources between the main thread and the write thread. During periods when no synchronization between threads is needed, the main thread freely accesses the the shared resources of the read and write threads. Then, when it wishes to supply work to be read or written, it sets up the shared resources to indicate the required work and then releases a condition variable to notify the read or write thread (as appropriate) that it should gather the request from the shared area. It then blocks itself until the requested thread completes its gathering of the request and releases a separate condition variable upon which it waits. In this way, the main thread in its normal state accesses the shared resource and then blocks itself by waiting on the condition during periods when its read or write thread needs access, whereas the read and write threads are opposite in that in their normal state they do not access the shared resource, but only do so during synchronization periods when the main thread has signaled and is waiting for them to complete their access.

Here is some very rough pseudo code (do not worry about exact flow here, this is just a rough idea of the functioning code):

MainThread:
  do {
    While (no pending requests) {
      manipulate shared resources;
    }
    if (need write && ready for read requests) {
      setup write request in shared resources;
      Release condition startWrite variable;
      Wait on condition endWrite variable;
    }
    if (need read && ready for read requests) {
      setup read request in shared resources;
      Release condition startRead variable;
      Wait on condition endRead variable;
    }
  }
ReadThread:
  do {
    Notify I am ready for read requests;
    Wait on condition startRead;
    copy request out of shared resources;
    update shared resources to account for reads completed;
    Release condition EndRead;
    Perform Read from disk;
  }
WriteThread:
  do {
    Notify I am ready for write requests;
    Wait on condition startWrite;
    copy request out of shared resources;
    update shared resources to account for writes completed;
    Release condition EndWrite;
    Perform write to disk;
  }

My question is whether this is considered just a normal producer consumer design pattern or whether there is a more specific commonly accepted design pattern that would describe what I have created?

  • 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-01T10:30:32+00:00Added an answer on June 1, 2026 at 10:30 am

    You’re getting some background activity to perform input and output, independently of the mainline processing. Reads can be scheduled ahead of time so the data is already there when needed, and writes can be farmed out to as a background activity so the mainline doesn’t have to block on comitting data to storage.

    This “design pattern” has a name, being known as “asynchronous IO”.

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

Sidebar

Related Questions

I have a multi-threaded application that is using pthreads. I have a mutex() lock
We have an application that creates several threads using the pthread library. As we
I have a multi-threaded application, I'm using pthreads with the pthread_mutex_lock function. The only
I have a VS2010 project which is a windows application that acquires data from
I have just started reading about threading in C, using pthreads. I know that
In general, if you have a class that inherits from a Thread class, and
I wrote an application using ASP.NET MVC, in this application I have an Index
I have a java-application using JDBC for database interaction. I want to do a
I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it
I have a lightweight application that catches Xorg and dbus events. In order to

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.