C++ malloc function doesn't work in Threads

Filip 831 Reputation points
2021-04-01T08:04:59.917+00:00

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

Developer technologies C++
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2021-04-01T08:14:19.09+00:00

    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.