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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:31:57+00:00 2026-05-28T18:31:57+00:00

Suppose there are several boost strand share_ptr stored in a vector m_poStrands. And tJobType

  • 0

Suppose there are several boost strand share_ptr stored in a vector m_poStrands. And tJobType is the enum indicated different type of job.
I found the time diff from posting a job in one strand (JOBA) to call the onJob of another strand (JOBB) is around 50 milli second.
I want to know if there is any way to reduce the time diff.

void postJob(tJobType oType, UINT8* pcBuffer, size_t iSize)
{
//...
    m_poStrands[oType]->post(boost::bind(&onJob, this, oType, pcDestBuffer, iSize));
}

void onJob(tJobType oType, UINT8* pcBuffer, size_t iSize)
{
       if (oType == JOBA)
       {
       //....
         struct timeval sTV;
    gettimeofday(&sTV, 0);
    memcpy(pcDestBuffer, &sTV, sizeof(sTV));
    pcDestBuffer += sizeof(sTV);
    iSize += sizeof(sTV);

    memcpy(pcDestBuffer, pcBuffer, iSize);

         m_poStrands[JOBB]->(boost::bind(&onJob, this, JOBB, pcDestBuffer, iSize));
       }
       else if (oType == JOBB)
       {
        // get the time from buffer
        // and calculate the dime diff
        struct timeval eTV;
        gettimeofday(&eTV, 0);
       }
}
  • 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-28T18:31:59+00:00Added an answer on May 28, 2026 at 6:31 pm

    Your latency is probably coming from the memcpys between your gettimeofdays. Here’s an example program I ran on my machine (2 ghz core 2 duo). I’m getting thousands of nanoseconds. So a few microseconds. I doubt that your system is running 4 orders of magnitude slower than mine. The worst I ever saw it run was 100 microsecond for one of the two tests. I tried to make the code as close to the code posted as possible.

    #include <boost/asio.hpp>
    #include <boost/chrono.hpp>
    #include <boost/bind.hpp>
    #include <boost/thread.hpp>
    #include <iostream>
    
    struct Test {
        boost::shared_ptr<boost::asio::strand>* strands;
        boost::chrono::high_resolution_clock::time_point start;
        int id;
    
        Test(int i, boost::shared_ptr<boost::asio::strand>* strnds)
            : id(i),
              strands(strnds)
        {
            strands[0]->post(boost::bind(&Test::callback,this,0));
        }
    
        void callback(int i) {
            if (i == 0) {
              start = boost::chrono::high_resolution_clock::now();
              strands[1]->post(boost::bind(&Test::callback,this,1));
            } else {
              boost::chrono::nanoseconds sec = boost::chrono::high_resolution_clock::now() - start;
              std::cout << "test " << id << " took " << sec.count() << " ns" << std::endl;
            }
        }
    };
    
    int main() {
        boost::asio::io_service io_service_;
        boost::shared_ptr<boost::asio::strand> strands[2];
        strands[0] = boost::shared_ptr<boost::asio::strand>(new boost::asio::strand(io_service_));
        strands[1] = boost::shared_ptr<boost::asio::strand>(new boost::asio::strand(io_service_));
        boost::thread t1 (boost::bind(&boost::asio::io_service::run, &io_service_));
        boost::thread t2 (boost::bind(&boost::asio::io_service::run, &io_service_));
        Test test1 (1, strands);
        Test test2 (2, strands);
        t1.join();
        t2.join();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose there is a script sth.py When i logged with 'root' account. type :
Suppose there were several projects mostly maintained by smart interns, who eventually leave after
Suppose there's a list of arguments stored somehow, in a array for example. Given
Suppose I have a variable counter, and there are several threads accessing and setting
Suppose there is a lot of vector shapes (Bezier curves which determine the boundary
Suppose I have several services represented by classes ServiceA, ServiceB, ServiceC etc. These services
Suppose there is a situation like : statement 1; statement 2; statement 3; statement
Suppose there are two lists a = {a1, a2, a3} and b = {b1,
Suppose there is an image_url column in database. I want the user to choose
Suppose there are ~10,000's of keys, where each key corresponds to a stream of

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.