#8798 closed bug (fixed)
PTHREAD_RWLOCK_INITIALIZER macro not defined
Reported by: | cian | Owned by: | nobody |
---|---|---|---|
Priority: | normal | Milestone: | Unscheduled |
Component: | System/POSIX | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
The pthread_rwlock functions exist in the header and I presume work, but the pthread_rwlock_initializer macro does not exist.
I've had to take a guess at the component, its likely not correct.
Attachments (4)
Change History (25)
comment:1 by , 12 years ago
Component: | Kits/Kernel Kit → System/libroot.so |
---|---|
Version: | R1/alpha3 → R1/Development |
comment:2 by , 12 years ago
Component: | System/libroot.so → System/POSIX |
---|---|
Owner: | changed from | to
comment:3 by , 10 years ago
Milestone: | R1 → Unscheduled |
---|
by , 8 years ago
Attachment: | 0001-pthread.h-Add-PTHREAD_RWLOCK_INITIALIZER-macro.patch added |
---|
Patch to define PTHREAD_RWLOCK_INITIALIZER
comment:6 by , 8 years ago
patch: | 0 → 1 |
---|
comment:7 by , 8 years ago
This macro is defined here http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlock_destroy.html and is also required for compiling with pthread support for Swift.
comment:9 by , 8 years ago
This patch assumes the implementation knows what to do with the values provided by pthread_rwlock_initializer, which it doesn't seem to. Best would be to provide a unit test for this, eventually.
comment:11 by , 8 years ago
by , 8 years ago
Attachment: | 0001-pthread_rwlock-draft-local-implementation.patch added |
---|
Try at implementing local pthread_rwlock
comment:12 by , 8 years ago
Tested on x86_64 only. I tried to implement again the local pthread_rwlock with mutexes. Might not be the best solution, the old one used block_thread and unblock_thread syscalls. Please review.
Another problem is the size of the struct _pthread_rwlock, it stays the same on x86_64 (40 bytes), not on x86 (was 32 bytes). I suppose we can reduce to only use 32 bytes on x86 and let 8 bytes unused on x86_64. Can this size actually change? Or are we stucked with these sizes for compatibility reasons?
comment:13 by , 8 years ago
Since Haiku introduced the pthread_* functions in the first place, and we didn't reach beta yet, I think it's fair to say that it's okay to break compatibility at this point. It would also be nice to be able to actually break old code visibly, not just let it crash in mysterious ways... Maybe we can achieve this with symbol versioning?
I would probably add a few bytes for future changes, though :-)
by , 8 years ago
Attachment: | 0001-pthread_rwlock-local-implementation-with-mutexes.patch added |
---|
reworked patch for local pthread_rwlock
comment:14 by , 8 years ago
@axeld I've changed the implementation to use only the first 32 bytes of the struct, so we could theoretically add a few bytes at the end: this should normally have no impact on existing binaries (TODO: remove the #ifdef B_HAIKU_64_BIT).
comment:15 by , 8 years ago
Unfortunately I don't have the time to thoroughly read the patch. From a quick glance: Not using a common waiting queue for readers and writers means that you can't treat both fairly. In this case it looks like writers can overtake waiting readers. As I wrote on the commit mailing list, I'd just replace the semaphore by a mutex and leave the implementation otherwise unchanged.
follow-up: 17 comment:16 by , 8 years ago
bonefish, yes readers and writers are treated unfairly in the patch, as in the specification: "The calling thread acquires the read lock if a writer does not hold the lock and there are no writers blocked on the lock.", which actually means that writers can overtake waiting readers. http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlock_rdlock.html
comment:17 by , 8 years ago
Replying to korli:
bonefish, yes readers and writers are treated unfairly in the patch, as in the specification: "The calling thread acquires the read lock if a writer does not hold the lock and there are no writers blocked on the lock.", which actually means that writers can overtake waiting readers. http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlock_rdlock.html
But that only means that a reader may not overtake an already waiting writer. In your implementation a new writer also overtakes an already waiting reader. While the specification doesn't seem to disallow that behavior, it means readers can be starved (which cannot happen with the current common queue implementation).
by , 7 years ago
Attachment: | 0001-pthread_rwlock-use-a-mutex-for-process-private-locks.patch added |
---|
try 3
comment:19 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Not seen a regression so far. Closing.
comment:20 by , 4 years ago
Is this still valid? It looks like latest VLC still needed a workaround.
comment:21 by , 4 years ago
No, it is definitely defined: https://github.com/haiku/haiku/blob/master/headers/posix/pthread.h#L83
The VLC patch may just be old and can be deleted.
Move POSIX compatibility related tickets out of R1 milestone (FutureHaiku/Features).