Files
XCEngine/docs/api/threading/read-write-lock/writelock.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

895 B

ReadWriteLock::WriteLock

void WriteLock()

获取写锁(独占)。如果有读者持有锁或有其他写者正在等待,当前线程将阻塞,直到获得独占访问权。

参数:

返回:

线程安全:

复杂度: 平均 O(1),写者饥饿时可能 O(n)

注意:

  • 写锁为独占访问,持有期间不允许任何读锁或写锁。
  • 写锁具有优先权,会阻塞后续到达的读者。
  • 同一线程不可重复 WriteLock。

示例:

#include "XCEngine/Threading/ReadWriteLock.h"
#include <vector>

XCEngine::Threading::ReadWriteLock rwLock;
std::vector<int> buffer;

void Append(int value) {
    rwLock.WriteLock();
    buffer.push_back(value);
    rwLock.WriteUnlock();
}

相关文档