Hacker News new | past | comments | ask | show | jobs | submit login

What eps means is that, currently you have a pointer to a mutex in your struct:

   struct chan_t { pthread_mutex_t* m_mu;... }
And initialize it like so:

    pthread_mutex_t* mu =
        (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
    pthread_mutex_init(mu, NULL);
    chan->m_mu = mu;
eps's suggestion is to put the mutex directly in the struct:

    struct chan_t { pthread_mutex_t m_mu;... }
and initialize it by passing its address to pthread_mutex_init:

    pthread_mutex_init(&chan->m_mu, NULL);
    chan->m_mu = mu;
that saves some mallocs and dereferences. If you are new to C, the notion of taking the address of fields in a struct may be unnerving, but you get used to it :)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: