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

  • Home
  • SEARCH
  • 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 7985731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:38:27+00:00 2026-06-04T11:38:27+00:00

this is the next step after this topic: Modifying data in threads class Nginx_sender

  • 0

this is the next step after this topic: Modifying data in threads

class Nginx_sender
{
    private:
        std::atomic_int data;
        boost::mutex mMutex;
   void SendMessage(const std::string &msg)
   {
       mMutex.lock();
       data++;
       mMutex.unlock();

       std::cout << "DATA: " << data << std::endl;
   }

   void NewThreadFunction()
   {
      while(true) {
        mMutex.lock();
         std::cout << data;
        mMutex.unlock();

        boost::this_thread::sleep(boost::posix_time::milliseconds(200));
      }
   }
};
int main()
{
   Nginx_sender *NginxSenderHandle;
   boost::thread sender(boost::bind(&Nginx_sender::NewThreadFunction, &NginxSenderHandle));
   // ...
}

In NewThreadFunction the data is always 0 and in SendMessage it changes each time I call SendMessage. So, what’s the right way to work with this?

  • 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-04T11:38:28+00:00Added an answer on June 4, 2026 at 11:38 am

    Remove the & from the second argument to bind. You already have a pointer to the object, and that’s what you’re likely trying to use. Secondly, the pointer is uninitialized which could also be a source of you problem. Note, you’ll have to be sure the object remains valid until the thread is joined.

    int main()
    {
       Nginx_sender *NginxSenderHandle = new Nginx_sender  ;
       boost::thread sender(boost::bind(&Nginx_sender::NewThreadFunction, NginxSenderHandle));
       // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an extension / next step of this question I asked a few
What does this mean: Next add reference to: MySql.Data actually I have downloaded mysql
i need some code for the next step..this my first step: <script> $(#mod).change(function() {
We have developed Air application and next step it is porting this application to
$(.editAd).change({ if ($(this).val() == 1) { $(#submitBtn).val(Next Step); } else { $(#submitBtn).val(Submit Changes); }
After getting OpenCover to work on my machine, the next step is getting it
$(function() { $(table.section thead).click(function() { if ($(this).next(table.section tbody).style.display == block){ $(this).next(table.section tbody).slideUp(slow); } if
I am using this code: $('.ui-accordion').bind('accordionchange', function(event, ui) { $(this).next().next().css({'background-image':'images/green-bg.jpg'}); //ui.newHeader // jQuery object,
Im using the following JS <a href=# onClick=if($(this).next('div').css('display') == 'none') { $(this).next('div').show('fast'); } else
I have the following jQuery which I need adapting: $(document).ready(function(){ $(.rss-popup a).hover(function() { $(this).next(em).stop(true,

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.