critical sections c++

Posted on 2012-08-17
Last Modified: 2012-09-12
Hi Experts,

I have a list of subscribers that I'm broadcasting an event to.  This list changes size at any time, so of course, before enumerating each listener and broadcasting to each, I need to be in a critical section block.  Is there any other way of doing this?  How expensive is it to be in this block (is there a good way to measure how expensive it is?)  I have a lot of events coming from a real-time device and I want to make sure they happen as fast as possible- while allowing for multiple subscribers for the events......

Thank you!
Question by:thready
    LVL 37

    Accepted Solution

    You could go into the critical section block and queue messages for everyone (which should be fairly instant). Then leave the critical section and send all the broadcast messages. This way you send to everyone but are only in the critical section a very short time.
    LVL 1

    Author Closing Comment

    This is a great answer!  Thanks!  :)

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    This is about my first experience with programming Arduino.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now