CK_COHORT_TRYLOCK(3)

πŸ’– CK_COHORT_TRYLOCK β€” try to acquire cohort lock πŸ’–

okay bestie, welcome to the CK_COHORT_TRYLOCK(3) page, it's giving concurrency, it's giving ✨lock energy✨, let's get into it 🫢


🌈 LIBRARY 🌈

Concurrency Kit, aka libck, and you link it with -lck πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <ck_cohort.h>

CK_COHORT_TRYLOCK(COHORT_NAME cohort_name, COHORT *cohort,
    void *global_trylock_context, void *local_trylock_context,
    void *lock_unlock_context);

✨ DESCRIPTION ✨

so this call right here? it tries to snag both the local lock and the global lock (but only if that's necessary, okay, it's not gonna do extra work for no reason 🧚) from cohort. iconique behaviour, no cap.

heads up though β€” you can only use this with cohort types that were defined using the CK_COHORT_TRYLOCK_PROTOTYPE(3) macro. wrong prototype, wrong vibe, it's not gonna work πŸ’€

the call will not block, periodt. it just returns a bool that evaluates to true iff the cohort was successfully acquired. that's it, that's the whole answer. lowkey elegant fr fr.

here's the tea on the contexts πŸ“:

  • global_trylock_context gets passed as the second argument to the function that was provided as the global_trylock_method argument to CK_COHORT_TRYLOCK_PROTOTYPE β€” but only if that method is actually called πŸ‘€
  • local_trylock_context gets passed to the function specified by local_trylock_method
  • and if the global lock acquisition fails? then the cohort will immediately release its local lock as well 😭 like, no hesitation, it's cleaning up after itself, main character energy honestly. when that happens, local_unlock_context gets passed to the function specified by local_unlock_method when this call is made.

(and yes bestie, the synopsis says lock_unlock_context while the description says local_unlock_context β€” that's just how the page is written, iykyk, we're keeping it exactly as it is πŸ™ˆ)


πŸ‘‘ SEE ALSO πŸ‘‘

more info lives at http://concurrencykit.org/ 🌸 go read it, slay


okay that's the whole page bestie, and this one was dated March 9, 2013. with the manual name CK_COHORT_TRYLOCK(3) β€” vintage but still ate πŸ’–βœ¨ bye ily πŸ¦‹

πŸ“¦ where this page comes from