I am creating a data parallel program using pthreads and C ++. From the pthread function from the class, I learned how to put a pthread_createpointer to a static C ++ function (and provide an argument to it this).
pthread_create
this
However, I also need to specify a stream with an index so that it knows what data it works on. I could malloccreate a structure for each thread (with both a pointer to the C ++ class and an index), but it looks like it will add some accounting code and may lead to leaks if the structure is not freed. Is there a better way to do this?
malloc
You can use Boost.Thread . It provides a safe way for you to pass more than one argument to your caller.
Yes, it has similar types of accounting, just like your question, but it uses C ++ mechanisms to ensure that it does not flow.
Is there a better way to do this?
. void *, , , , . ThreadParameters , , , , .
void *
ThreadParameters
, , , ThreadParameters, ThreadParameters .
++ this , .
, , . this , .
, delete pthread_join. .
delete
pthread_join
( ), . ( this.) . .
class C { Index index_; public: C(Index &index) : index_(idx) {} void Run() { ... } } Index workSet; C worker(workSet); worker.Run();
Source: https://habr.com/ru/post/1731088/More articles:How to populate a WebBrowser TextBox? - c #ELF General Library: Offset Offset Offset - gccParsing cookie headers in J2ME / BlackBerry apps - javawhat order when choosing data from a database? - sqlУменьшение базы данных на Android - androidHow do I create a signature for a billing request in the Amazon FPS Marketplace? - signatureBuilding dates in TSQL - sqlБиблиотека с плавающей запятой для встроенного приложения - cOpenId - return returnTo url with POST instead of GET - openidHow to create an executable application for Excel macro? - c #All Articles