Files
XCEngine/docs/api/threading/read-write-lock/readlock.md
ssdfasd f427699ac6 refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
  instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
  test discovery (math, core, containers, memory, threading, debug,
  components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
  from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
  build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00

42 lines
854 B
Markdown

# ReadWriteLock::ReadLock
```cpp
void ReadLock()
```
获取读锁。如果有写者持有锁或正在等待写锁,当前线程将阻塞,直到所有写者完成。
**参数:**
**返回:**
**线程安全:**
**复杂度:** 平均 O(1)
**注意:**
- 多个读者可以同时持有读锁。
- 写锁具有优先权——正在等待的写者会阻塞新的读者,防止写者饥饿。
- 读锁不可重入,同一线程不可嵌套持有读锁。
**示例:**
```cpp
#include "XCEngine/Threading/ReadWriteLock.h"
XCEngine::Threading::ReadWriteLock rwLock;
int sharedValue = 0;
int ReadValue() {
rwLock.ReadLock();
int value = sharedValue;
rwLock.ReadUnlock();
return value;
}
```
## 相关文档
- [`ReadWriteLock`](readwritelock.md) - 返回类总览
- [`ReadUnlock`](readunlock.md) - 释放读锁