Problem description:
Our applications adopt a mechanism of shared memory and read/write locks to achieve concurrent access to multiple processes. However, we found that there was a problem with the read/write locks during the test, the locks we use are pthread_rwlock_rdlock and pthread_rwlock_wrlock.
Symptom:
Pthread_rwlockattr_setpshared (& ATTR, pthread_process_shared); If a call error occurs, code 38 is returned. The reason is that the system does not support this function.
System Environment:
Uname-
Linux s12084 2.6.9-67. elsmp #1 SMP wed Nov 7 13:58:04 est 2007 i686 i686 i386 GNU/Linux
G ++ 3.2.3
Solution:
Because we have run in this environment before, we suspect that it may be a patch or system version problem. Later we found the following line in. bash_profile:
Export ld_assume_kernel = 2.4.19 # For building ORACLE DB
It turns out this was added when oracle was installed. It was added only when oracle was installed.
In this case, check the test program about the read/write lock and execute: LDD locktest.
/Lib/libcwait. So (0x00eb0000)
Libpthread. so.0 =>/lib/i686/libpthread. so.0 (0x003d3000) ---- The libpthread used below is not a library in the same directory.
After unset ld_assume_kernel is executed
Run: LDD locktest
/Lib/libcwait. So (0x00f19000)
Libpthread. so.0 =>/lib/tls/libpthread. so.0 (0x00b8e000) --- The libpthread used in the TLS directory can ensure the correctness of the read/write lock. The above does not support read/write locks.
By removing ld_assume_kernel, the system is connected to libpthread. so.0 In the TLS directory, and the read lock function is normal.
For details about the thread library in Linux, refer:
The http://www.cublog.cn/u/6303/showart_472641.html has a detailed explanation of this problem.
Through this problem, it is also explained that the support for read/write locks between processes is problematic in versions earlier than linux2.4.19, or is not supported.
For more information, see http://www.ibm.com/?works/cn/linux/porting/solaris/guide1/index.html:
"
To use POSIX ThreadsRead/write lockExtension, which must be defined at Compilation:
_XOPEN_SOURCE=500
This must be completed before the <pthread. h> header file is added. You must also define the following:
_POSIX_C_SOURCE=199506L
Linux threads do not implement mutual exclusion, conditions, and signals of shared processes. The purpose of this extension is to allow different processes (processes with different address spaces) in the shared memory (svr4 shared memory fragments or mapped MMAP () files) the allocated mutex, conditions, or signals are synchronized. "
According to the above operation is not supported, the kernel must be used together.