question

Filip-2434 avatar image
0 Votes"
Filip-2434 asked Viorel-1 edited

C++ malloc function doesn't work in Threads

Hello everybody
How can I use "malloc()" in c++?
I use these code https://github.com/engineer-man/youtube/blob/master/011/mutexes.c but it show error. Where is section with malloc().
Shoudl i use something?
Thanks for answare,

83623-snimka-obrazovky-2021-04-01-095732.png


c++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
1 Vote"
Viorel-1 answered Viorel-1 edited

Try something like this:

 pthread_t thread_group[MAX_CORES];

 or
    
 pthread_t *thread_group = new pthread_t[MAX_CORES];
    
 or
    
 pthread_t *thread_group = (pthread_t*)malloc(sizeof(pthread_t) * MAX_CORES);

Or change the file extension to .c.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.