PTHREAD_RWLOCKATTR_SETKIND_NP(3)

✨ NAME ✨

okay bestie, gather round πŸ’– this is the manual page for pthread_rwlockattr_setkind_np, pthread_rwlockattr_getkind_np β€” and they're here to set/get the read-write lock kind of the thread read-write lock attribute object. that's it, that's the whole job. πŸ’…


πŸ“š LIBRARY πŸ“š

POSIX threads library β€” libpthread, -lpthread. yeah you gotta link it, no cap. πŸ”—


🩷 SYNOPSIS 🩷

#include <pthread.h>

int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t *attr,
                       int pref);
int pthread_rwlockattr_getkind_np(
                       const pthread_rwlockattr_t *restrict attr,
                       int *restrict pref);

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

pthread_rwlockattr_setkind_np(), pthread_rwlockattr_getkind_np():
    _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200809L
bestie listen 😭 these macros are the bouncers at the club. no matching <italic>feature test macro</italic>, no entry, and the function literally doesn't exist for you. pls define them before you #include anything.

🌸 DESCRIPTION 🌸

so pthread_rwlockattr_setkind_np() sets the "lock kind" attribute of the read-write lock attribute object referred to by attr to the value you put in pref. lowkey simple. ✨

the argument pref may be set to one of these three icons only πŸ‘‘:

  • PTHREAD_RWLOCK_PREFER_READER_NP β€” the default, the main character, the one you get if you say nothing πŸŽ€. a thread may hold multiple read locks; that is, read locks are recursive. according to The Single Unix Specification, the behavior is unspecified when a reader tries to place a lock, and there is no write lock but writers are waiting 😬. giving preference to the reader, as is set by PTHREAD_RWLOCK_PREFER_READER_NP, implies that the reader will receive the requested lock, even if a writer is waiting. as long as there are readers, the writer will be starved. yes, starved. that writer is in the group chat typing and nobody's reading πŸ’€.
  • PTHREAD_RWLOCK_PREFER_WRITER_NP β€” this is intended as the write lock analog of PTHREAD_RWLOCK_PREFER_READER_NP. and now the plot twist: this is ignored by glibc πŸ™ˆ because the POSIX requirement to support recursive read locks would cause this option to create trivial deadlocks. so instead use PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, which ensures the application developer will not take recursive read locks thus avoiding deadlocks. it's giving "we love you but we're not doing what you asked" fr fr.
  • PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP β€” setting the lock kind to this avoids writer starvation as long as any read locking is not done in a recursive fashion. the one that actually eats. πŸ”₯

and pthread_rwlockattr_getkind_np() returns the value of the lock kind attribute of the read-write lock attribute object referred to by attr in the pointer pref. it reads it back and hands it to you, no drama. 🫢


⭐ RETURN VALUE ⭐

on success, these functions return 0. iconic. periodt.

given valid pointer arguments, pthread_rwlockattr_getkind_np() always succeeds. it literally cannot fail on you, bestie, it's that reliable 🧚.

on error, pthread_rwlockattr_setkind_np() returns a nonzero error number. so like, check it, don't be out here ignoring return values, that's not the vibe. 😭


πŸ’€ ERRORS πŸ’€

  • EINVAL β€” pref specifies an unsupported value. you made up a lock kind, girl. it is not real. it is not valid. go pick one of the three. πŸ™ˆ

🌈 STANDARDS 🌈

GNU. hence the suffix _np in the names β€” "(nonportable)". it's nonportable on purpose, that's its whole brand πŸ’…. don't expect this energy to travel.


πŸ’œ HISTORY πŸ’œ

glibc 2.1. ancient. historic. still here, still slaying. πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page bestie!! πŸ’–βœ¨ this legendary lore comes to you from Linux man-pages 6.20, dated 2026-02-08 β€” the pthread_rw..._setkind_np(3) era πŸŽ€πŸ«Ά go forth and set your lock kinds responsibly, mwah πŸ’…

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms