Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues while profiling multithreading applications #63

Open
ktf opened this issue Jul 7, 2015 · 0 comments
Open

Issues while profiling multithreading applications #63

ktf opened this issue Jul 7, 2015 · 0 comments

Comments

@ktf
Copy link
Contributor

ktf commented Jul 7, 2015

The following does not get profiled correctly, only one of the two functions are getting reported.

#include <vector>
#include <thread>
#include <unistd.h>

void myfunctionA() {
   int a = 0;
   for (int i = 0; i < 100000000; i++)
       for (int j = 0; j < 20; j++)
           a = a * 2 / 5 * 10;
}

void myfunctionB() {
   int a = 0;
   for (int i = 0; i < 100000000; i++)
       for (int j = 0; j < 20; j++)
           a = a * 2 / 5 * 10;
}

int main()
{
  std::vector<std::thread> threads;
  int num_threads = 2;
  for (int i = 0; i < num_threads; ++i) {
      auto f = [](int j) {
           if (j==0) {
               printf("A\n");
               myfunctionA();
           }
           else {
               printf("B\n");
               myfunctionB();
           }
      };
      threads.emplace_back(f,i);
  }

  for(auto& thread: threads) {
     thread.join();
  }

  return 0;
}

This is just a placeholder for further discussion if anyone has time to look into this (I don't at the moment).
@dpiparo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant