Hello,
I am trying to insert multiple threads into an application. Here's my procedure:
1. The original application uses pthread_create, and is compiled and linked against it.
2. I use drwrap_replace to replace the application's main with my own. This works pretty well, I inserted a bunch of couts in the replacement main and they print fine, it exits without errors too.
3. In the same replacement main, I started inserting calls to pthread_create and pthread_join. The prints still execute OK, but once it reaches pthread_create for the first time, it segfaults right away.
4. So far, I have been compiling without linking with the pthread library (probably why it seg faults when it hits pthread_create?). If I start linking against it, as expected, the entire client breaks down.
5. It is worth noting that I also drwrap_wrap the calls to pthread_create so I can have the freedom to modify its arguments, the pre wrappers are never called too.
So, how do I solve this? what is the proper way to compile this replacement main function so that pthread_create would execute?
For reference, here's the replacement function:
void* PlaceholderThread(void* args)
{
return nullptr;
}
int ReplacementMain(int argc, char** argv)
{
pthread_t thread[argc];
std::cout << "Start\n";
for (int i = 0; i < argc; i++)
{
pthread_create(&thread[i], nullptr, &PlaceholderThread, nullptr);
}
std::cout << "Middle\n";
for (int i = 0; i < argc; i++)
{
pthread_join(0, nullptr);
}
std::cout << "End\n";
return 0;
}