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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:22:36+00:00 2026-06-07T05:22:36+00:00

Assume I have shared double variable. Thread A updates it several thousands times per

  • 0

Assume I have shared double variable. Thread A updates it several thousands times per second. In another thread B I want to be notified somehow about “update” every time this happens.

I was tried to avoid notifications completely and just use while(true) loop but this introduced significant slowdowns into my program lock-free calc: how to sum N double numbers that are changing by other threads? probably because of that “Meanwhile you keep on loading that same array from memory over and over which is not really good for performance since memory bandwith is limited.”

I’ve also tried using Monitor class but it was also pretty slow and I’ve seen up to 1-2 ms delays when Monitor.TryEnter return false.

I now think that I need to do notifications using lock-free technique, probably using SpinLock or something else?

  • 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-07T05:22:38+00:00Added an answer on June 7, 2026 at 5:22 am

    Use wait handle to notify between threads

        System.Threading.AutoResetEvent are = new System.Threading.AutoResetEvent(false);
        double d = 0;
        public void ThreadA(object state)
        {
            while (true)
            {
                d++;
                are.Set();
            }
        }
    
        public void ThreadB(object state)
        {
            while (true)
            {
                are.WaitOne();
                double current = d;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume we have a multithreaded C program (pthreads), and the (unsynchronized) shared variable accesses
I have a question on shared libraries vs static libraries loading time. Assume that
Assume for a second we have #include <boost/shared_ptr.hpp> #include <iostream> int main() { boost::shared_ptr<int>
I have to manually migrate a Joomla website to another server (shared hosting). Our
Assume you have a reference counted object in shared memory. The reference count represents
I have compiled shared libraries dynamically linked against libstdc++.so using GLIBCXX_3.4.11. I want to
I am planning to use a shared variable to implement a logging facility. Have
Assume I have a C# class like this: [XmlRoot(floors)] public class FloorCollection { [XmlElement(floor)]
Assume I have the following string: Hellotoevryone<img height=115 width=150 alt= src=/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg />Iamsogladtoseeall. This
Assume I have access to a SMB server at IP 1.2.3.4, how can I

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.