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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:37:34+00:00 2026-05-18T22:37:34+00:00

I’m refactoring a project that I did not design. It is written in C/C++

  • 0

I’m refactoring a project that I did not design. It is written in C/C++ for linux. The project has a major client component that looks like this:

Client -> Output Queuing Library (OQL) -> Controller

Client

  • Messy semi-complex code, poorly designed (hodgepodge of OOP approximations using singletons/namespaces, just weird in many places – but it works)
  • Custom protocol implementation (not my protocol, cannot modify)
  • Shared Library
  • Multi-threaded
    • Multiple threads call the OQL api, ie multiple threads output
  • Accepts commands from controller via API
  • Produces massive unsequenced output which is affected but not necessarily directly (and definitely not 1:1) by the controller input)

Output Queuing Library (OQL)

  • Simple clean code, not really designed for it’s current workload (was never meant to queue, was actually originally just writing to stdout and then a message queue was shoe-horned in)
  • Shared Library
  • Single-threaded
  • Exposes API which accepts many types of data from the client and builds textual representations of this data
  • Inserts data into a sys V message queue

Controller

  • Executable
  • Single-threaded
  • Elegant, fault tolerant C++ which makes extensive use of boost
  • Written from scratch by me, the only part of the project I’ve been allowed to completely “fix” so to speak
  • Interacts with client library via API to initiate connection to server
    • Saves data produced by Client and read from OQL into database in another layer

So the problem essentially boils down to this, the controller is single threaded and calls many API functions in the client library. Scenarios resulting from Controller calling Client API.

  1. Normal (98%+)
    1. Controller calls client API function
    2. Client API function does magic internally
    3. API function returns true
    4. Client receives data as a result of magic in step 2, in another thread of execution and calls OQL put function from a secondary thread
    5. OQL writes data to message queue, queue either blocks or does not block but neither matter since the controller’s main thread of execution is running and processing data.
    6. Success!
  2. Problem Scenario
    1. Controller calls client API function
    2. Client API function immediately produces result and BEFORE returning calls OQL put function from the main thread of execution in the Controller
    3. OQL writes data to the message queue and one of the following happens:
      1. Message queue is not full, does not block, everything returns and the controller processes the new data in the message queue and life moves on happily
      2. Problem Scenario Message queue IS full and DOES block

Now what I’m sure you can see is in the problem scenario, which is rare, the main thread of execution is blocking on a full message queue and also no data is being processed off of the other end of the queue since the controller is single threaded…

So yes it’s a bit of a mess, and no I’m not happy with the design but I’ve gotta figure out the best way to solve this without rewriting all of these interactions.

I’m trying to decide between:

  1. Digging into the client, synchronizing all of the threads to a single I/O thread that interacts with OQL

    • I have basically zero faith that someone after me will not come in and break this down the road, introduce massive bugs and not be able to understand why
  2. Introducing a writer thread into OQL

    • Takes a simple class and complicates it significantly
    • Introduces funny problems
      • Doesn’t the queue need a queue at that point? Since data has to get transported to the writer thread

Really just typing up this question was probably the best thing I could have done, since my thoughts are much more organized now…but does anyone have any input to offer here? Is there some design pattern I’m not seeing which would not require massive refactoring, and are my concerns overblown on either of these? I’m not even sure if it’s possible for anyone to provide meaningful advice here without knowing all angles of the problem, but I appreciate any insight you guys can offer.

  • 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-18T22:37:35+00:00Added an answer on May 18, 2026 at 10:37 pm

    You could change the Controller to use a second thread to do the reading from the message queue (and just post the data to a much larger buffer, internal to the Controller, to be read by the main Controller thread).

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.