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++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Viorel 125.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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.