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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:07:31+00:00 2026-05-25T03:07:31+00:00

I am looking for a way to optimize the following code, for an open

  • 0

I am looking for a way to optimize the following code, for an open source project that I develop, or make it more performant by moving the heavy work to another thread.

void ProfilerCommunication::AddVisitPoint(ULONG uniqueId)
{
    CScopedLock<CMutex> lock(m_mutexResults);
    m_pVisitPoints->points[m_pVisitPoints->count].UniqueId = uniqueId;
    if (++m_pVisitPoints->count == VP_BUFFER_SIZE)
    {
        SendVisitPoints();
        m_pVisitPoints->count=0;
    } 
}

The above code is used by the OpenCover profiler (an open source code coverage tool for .NET written in C++) when each visit point is called. The mutex is used to protect some shared memory (a 64K block shared between several processes 32/64 bit and C++/C#) when full it signals the host process. Obviously this is quite heavy for each instrumentation point and I’d like to make the impact lighter.

I am thinking of using a queue which is pushed to by the above method and a thread to pop the data and populate the shared memory.

Q. Is there a thread-safe queue in C++ (Windows STL) that I can use – or a lock-less queue as I wouldn’t want to replace one issue with another? Do people consider my approach sensible?


EDIT 1: I have just found concurrent_queue.h in the include folder – could this be my answer…?

  • 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-25T03:07:31+00:00Added an answer on May 25, 2026 at 3:07 am

    Okay I’ll add my own answer – concurrent_queue works very well

    using the details described in this MSDN article I implemented concurrent queue (and tasks and my first C++ lambda expression 🙂 ) I didn’t spend long thinking though as it is a spike.

    inline void AddVisitPoint(ULONG uniqueId) { m_queue.push(uniqueId); }
    
    ...
    // somewhere else in code
    
    m_tasks.run([this]
    {
        ULONG id;
        while(true)
        {
             while (!m_queue.try_pop(id)) 
                Concurrency::Context::Yield();
    
            if (id==0) break; // 0 is an unused number so is used to close the thread/task
            CScopedLock<CMutex> lock(m_mutexResults);
            m_pVisitPoints->points[m_pVisitPoints->count].UniqueId = id;
            if (++m_pVisitPoints->count == VP_BUFFER_SIZE)
            {
                SendVisitPoints();
                m_pVisitPoints->count=0;
            }
        }
    });
    

    Results:

    • Application without instrumentation = 9.3
    • Application with old instrumentation handler = 38.6
    • Application with new instrumentation handler = 16.2
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a way to optimize one SQL query that I have. I'm
I'm currently looking for a way to optimize a process that takes a long
I looking for a way, specifically in PHP that I will be guaranteed to
I'm looking for a way to optimise the following: SELECT (SELECT SUM(amount) FROM Txn_Log
i'm looking for a way to make the menu system of my (very first)
I am looking to optimize a fairly simple algorithm that is currently O(n 2
Im looking to optimize our translation workflow for a django/python based project. Currently we
Currently I am working on a project that would use genetic algorithms to optimize
I am looking for a way to make speedy modifications to large multi-gigabyte files.
I am looking for the fastest way to de/interleave a buffer. To be more

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.