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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:54:49+00:00 2026-06-15T00:54:49+00:00

I’m working on a Multi Threaded application programmed in C++. I uses some temporary

  • 0

I’m working on a Multi Threaded application programmed in C++. I uses some temporary files to pass data between my threads. One thread writes the data to be processed into files in a directory. Another thread scans the directory for work files and reads the files and process them further, then delete those files. I have to use these files , because if my app gets killed when , i have to retain the data which has not been processed yet.

But i hate to be using multiple files. I just want to use a single file. One thread continuously writing to a file and other thread reading the data and deleting the data which has been read.
Like a vessel is filled from top and at bottom i can get and delete the data from vessel. How to do this efficiently in C++ , first is there a way ..?

  • 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-15T00:54:50+00:00Added an answer on June 15, 2026 at 12:54 am

    As was suggested in the comments to your questions using a database like SQLite may be a very good solution.
    However if you insist on using a file then this is of course possible.

    I did it myself once – created a persistent queue on disk using a file.

    Here are the guidelines on how to achieve this:

    1. The file should contain a header which point to the next unprocessed record (entry) and to the next available place to write to.
    2. If the records have variable length then each record should contain a header which states the record length.
    3. You may want to add to each record a flag that indicates whether the record was processed
    4. file locking can be used to ensure no one reads from the portion of the file that is being written to
    5. Use low level IO – don’t use buffered streams of any kind, use direct write semantics

    And here is the schemes for reading and writing (probably with some small logical bugs but you should be able to take it from there):

    READER

    1. Lock the file header and read it and unlock it back
    2. Go to the last record position
    3. Read the record header and the record
    4. Write the record header back with the processed flag turned on
    5. If you are not at the end of file Lock the header and write the new location of the next unprocessed record else write some marking to indicate there are no more records to process
    6. Make sure that the next record to write points to the correct place

    You may also want the reader to compact the file for you once in a while:

    1. Lock the entire file
    2. Copy all unprocessed records to the beginning of the file (You may want to keep some logic as not to overwrite your unprocessed records – maybe compact only if processed space is larger than unprocessed space)
    3. Update the header
    4. Unlock the file

    WRITER

    1. Lock the header of the file and see where the next record is to be written then unlock it
    2. Lock the file from the place to be written to the length of the record
    3. Write the record and unlock
    4. Lock the header if the unprocessed record mark indicates there are no records to process let it point to the new record unlock the header

    Hope this sets you on the write track

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.