C++ multithreading

   522   3   2
User Avatar
Member
9 posts
Joined: June 2018
Offline
Hi,

I want to create threads using(CreatingChildThreads):
https://www.sidefx.com/docs/hdk/_h_d_k__multi_threading.html#HDK_MultiThreading_CreatingChildThreads [www.sidefx.com]

This code executes the doTask function on each thread.
threads(i)->startThread(&doTask, data)

How can I alter the doTask function with my own set of inputs?
For example (tried to do this but it did not work):

static void *
doTask(void *data, vector<double> myArray, int idx)
{
    myArray[idx] += 1.0;
    return NULL; // always return NULL
}

threads(i)->startThread(&doTask, data, myArray, idx)
User Avatar
Member
28 posts
Joined: July 2022
Offline
doTask can only have one parameter.
Try converting a struct to void * data through `static_cast`.
```
struct S
{
vector<double> myArray;
int idx;
}
```
User Avatar
Member
7734 posts
Joined: July 2005
Offline
For most compute tasks I recommend using UTparallelFor() [www.sidefx.com] instead.
User Avatar
Member
9 posts
Joined: June 2018
Offline
Thanks! I'm quite new to the HDK documentation and c++ in general, I'll test both methods!
  • Quick Links