pthread_rwlock problem

Alexey Salmin alexey.salmin@gmail.com
Sun Oct 19 10:59:00 GMT 2008


Hello!
I'm not quite sure this mail was sent to a proper place but anyway I
hope I'll get some help :)
Trying to understand the way NPTL works I wrote a simple program which
uses the base
pthread_rwlock functionality (see the attached file). But it doesn't
work and I have no idea why.
My program contains an integer variable protected with pthread_rwlock.
It can execute two
simple command: "r" and "w NNN", where NNN is an integer value. When
you type 'r' symbol
to it's stdin pthread_rwlock_rdlock is being hold for 5 seconds and
stored value is being
written to the stdout. "w" command holds pthread_rwlock_wrlock for 5
second and changes
the data. Here's the text from the pthread_rwlock_rdlock manual :"The
pthread_rwlock_rdlock()
function shall apply a read lock to the read-write lock referenced by
rwlock. The calling thread
acquires the read lock if a writer does not hold the lock and (!)
there are no writers blocked on the lock (!)."
So the expected result for the "r w 10 r" command string is "0 10".
But actually it is "0 0".
It means that the second "r" command get the lock while the "w"
operation is being blocked.

I compile my program this way: "gcc main.c -o main -l pthread -std=gnu99"

My system info:
salmin@salmin:~$ uname -a
Linux salmin 2.6.26-1-amd64 #1 SMP Wed Sep 24 13:59:41 UTC 2008 x86_64 GNU/Linux
ii  gcc                       4:4.3.2-2                 The GNU C compiler
ii  libc6                     2.7-15                    GNU C Library:
Shared libraries

PS Sorry for my language :)

Alexey
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.c
Type: text/x-csrc
Size: 2330 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20081019/b1078f58/attachment.bin>


More information about the Gcc-help mailing list