Inserting pthread_create call into sequential code


I was working on multithreading a cross iteration loop. I want to insert a pthread_create function call and use other pthread functions into my LLVM IR.

Issue is how do i get these functions using module->getOrInsertFunction(“pthread_create”), since the function might not be there in IR and then insert function calls to these functions.

So, crux is how do i call pthread function calls into LLVM IR for a sequential program.

Pardon me for such a basic doubt as I am a novice in llvm yet.

Pankit Thapar

One quick way you could investigate this is by using the LLVM demo
page (or the LLVM cpp backend). It's not perfect,
but might do in a pinch.

by compiling simple code like:

void my_func();

int main() {

& targeting the cpp backend ("LLVM C++ API code") you can see what
kind of C++ code you might need to write to call an external function.
Then calling pthread_create or any other function is just a matter of
getting the signature right, basically.

- David