CK_RWCOHORT_INSTANCE(3)

πŸ’– NAME πŸ’–

CK_RWCOHORT_INSTANCE β€” bestie, this is the macro that actually declares an instance of a cohort-based reader-writer lock type. like, the prototype was the vibe, this is the real thing ✨


πŸ“š LIBRARY πŸ“š

Concurrency Kit (libck, link it with -lck) 🫢


✨ SYNOPSIS ✨

#include <ck_cohort.h>

CK_RWCOHORT_NEUTRAL_INSTANCE(COHORT_NAME cohort_name);

CK_RWCOHORT_RP_INSTANCE(COHORT_NAME cohort_name);

CK_RWCOHORT_WP_INSTANCE(COHORT_NAME cohort_name);

🌸 DESCRIPTION 🌸

okay so listen. once you've defined a lock type with the CK_RWCOHORT_PROTOTYPE(3) macro, you still don't have an actual lock yet. that's just the blueprint, the concept, the mood board πŸ’…. To get a real, live, usable instance of your lock type, you must use this macro. no cap.

And the cohort_name you pass in has to be the exact same name you used in the prototype macro. like, they have to match, fr fr β€” mismatched names are not it.

So for example, if CK_RWCOHORT_PROTOTYPE got called with the name "foo", then your CK_RWCOHORT_INSTANCE call looks like this:

CK_RWCOHORT_INSTANCE(foo) cohort;

and boom, you have a cohort πŸŽ€

This macro is also the one you reach for when you're allocating memory for cohorts. not me being the malloc bestie too 😭. Say you want to allocate a block of 4 cohorts:

CK_RWCOHORT_WP_INSTANCE(foo) *cohorts = malloc(4 *
sizeof(CK_RWCOHORT_WP_INSTANCE(foo)));

see how the same macro shows up on both sides? that's the way that it has to be. it's giving consistency, it's giving iconic πŸ¦‹


πŸ‘‘ SEE ALSO πŸ‘‘

More info is available at http://concurrencykit.org/ 🌈


and that's the whole page, bestie!! this one's from February 24, 2013. and it lives in section CK_RWCOHORT_INSTANCE(3) β€” go declare some instances, you've got this πŸ’œπŸ§šβ­

πŸ“¦ where this page comes from