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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:08:20+00:00 2026-05-14T01:08:20+00:00

I need to implement a statistics reporter – an object that prints to screen

  • 0

I need to implement a statistics reporter – an object that prints to screen bunch of statistic.
This info is updated by 20 threads.

The reporter must be a thread itself that wakes up every 1 sec, read the info and prints it to screen.

My design so far: InfoReporterElement – one element of info. has two function, PrintInfo and UpdateData.
InfoReporterRow – one row on screen. A row holds vector of ReporterInfoElement.
InfoReporterModule – a module composed of a header and vector of rows.
InfoRporter – the reporter composed of a vector of modules and a header. The reporter exports the function ‘PrintData’ that goes over all modules\rows\basic elements and prints the data to screen.

I think that I should an Object responsible to receive updates from the threads and update the basic info elements.

The main problem is how to update the info – should I use one mutex for the object or use mutex per basic element?
Also, which object should be a threads – the reporter itself, or the one that received updates from the threads?

  • 1 1 Answer
  • 1 View
  • 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-14T01:08:20+00:00Added an answer on May 14, 2026 at 1:08 am

    I would say that first of all, the Reporter itself should be a thread. It’s basic in term of decoupling to isolate the drawing part from the active code (MVC).

    The structure itself is of little use here. When you reason in term of Multithread it’s not so much the structure as the flow of information that you should check.

    Here you have 20 active threads that will update the information, and 1 passive thread that will display it.

    The problem here is that you encounter the risk of introducing some delay in the work to be done because the active thread cannot acquire the lock (used for display). Reporting (or logging) should never block (or as little as possible).

    I propose to introduce an intermediate structure (and thread), to separate the GUI and the work: a queuing thread.

    • active threads post event to the queue
    • the queuing thread update the structure above
    • the displaying thread shows the current state

    You can avoid some synchronization issues by using the same idea that is used for Graphics. Use 2 buffers: the current one (that is displayed by the displaying thread) and the next one (updated by the queuing thread). When the queuing thread has processed a batch of events (up to you to decide what a batch is), it asks to swap the 2 buffers, so that next time the displaying thread will display fresh info.

    Note: On a more personal note, I don’t like your structure. The working thread has to know exactly where on the screen the element it should update is displayed, this is a clear breach of encapsulation.

    Once again, look up MVC.

    And since I am neck deep in patterns: look up Observer too 😉

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

Sidebar

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.