Skip to content

feat: Phase 10 — std::shared_mutex для read-only методов - #25

Merged
netkeep80 merged 4 commits into
netkeep80:mainfrom
konard:issue-5-6056bb6aa7e5
Mar 1, 2026
Merged

feat: Phase 10 — std::shared_mutex для read-only методов#25
netkeep80 merged 4 commits into
netkeep80:mainfrom
konard:issue-5-6056bb6aa7e5

Conversation

@konard

@konard konard commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

Что реализовано

Решает задачу из issue #5: реализована следующая задача текущей фазы плана — Фаза 10: std::shared_mutex.

Суть изменений

Переход с std::recursive_mutex на std::shared_mutex:

Тип методов Блокировка Параллельность
Писатели (create, load, destroy, allocate, deallocate) std::unique_lock<std::shared_mutex> Эксклюзивная
Читатели (validate, save, dump_stats) std::shared_lock<std::shared_mutex> Параллельная ✅

Ключевые изменения

include/persist_memory_manager.h

  • std::recursive_mutexstd::shared_mutex (версия 0.7.00.8.0)
  • Write-методы: lock_guard<recursive_mutex>unique_lock<shared_mutex>
  • Read-методы (validate, save, dump_stats): добавлен shared_lock<shared_mutex>
  • reallocate() рефакторирован: вызывает lock.unlock() перед allocate()/deallocate() — устраняет deadlock с нерекурсивным мьютексом. Попутно сокращён с 41 до 35 строк.
  • Размер файла: 1499 строк (лимит CI ≤ 1500 ✅)

tests/test_shared_mutex.cpp (новый, 313 строк)

4 теста:

  1. test_concurrent_validate — 8 потоков параллельно вызывают validate() (shared_lock)
  2. test_readers_writers — 4 читателя + 2 писателя одновременно
  3. test_reallocate_correctness — корректность данных при параллельном reallocate
  4. test_concurrent_get_stats — согласованность счётчиков при параллельном get_stats

Документация

  • phase10.md — документация по Фазе 10
  • plan.md — добавлена Фаза 10 (статус: ✅ Завершена)
  • README.md — обновлено описание возможностей и структура репозитория

Результаты CI

  • ✅ Все 9 тестов проходят (8 предыдущих + 1 новый test_shared_mutex)
  • clang-format без нарушений
  • cppcheck без предупреждений
  • ✅ Размер файла ≤ 1500 строк

Fixes #5

konard and others added 2 commits March 1, 2026 07:04
Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: netkeep80#5
Replace std::recursive_mutex with std::shared_mutex to enable parallel
readers (validate, save, dump_stats) while keeping exclusive write access
for allocate, deallocate, create, load, destroy.

Key changes:
- include/persist_memory_manager.h: swap recursive_mutex → shared_mutex;
  write methods use unique_lock, read methods use shared_lock;
  refactor reallocate() to release lock before calling allocate/deallocate
  (avoids deadlock with non-recursive shared_mutex); version → 0.8.0
- tests/test_shared_mutex.cpp: 4 tests — concurrent validate, readers +
  writers, reallocate correctness, concurrent get_stats
- tests/CMakeLists.txt: add test_shared_mutex target
- phase10.md: documentation for Phase 10
- plan.md, README.md: updated to reflect Phase 10 completion

File size: 1499 lines (CI limit ≤ 1500 ✅)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] Реализовать следующую задачу в текущей фазе плана и после обновить plan.md , README.md и отдельный файл фазы разработки feat: Phase 10 — std::shared_mutex для read-only методов Mar 1, 2026
@konard
konard marked this pull request as ready for review March 1, 2026 07:14
@konard

konard commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $4.928851
  • Calculated by Anthropic: $3.741408 USD
  • Difference: $-1.187443 (-24.09%)
    📎 Log file uploaded as Gist (3611KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard

konard commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

🔄 Auto-restart triggered

Reason: CI failures detected

Starting new session to address the issues.


Auto-restart-until-mergeable mode is active. Will continue until PR becomes mergeable.

Multi-threaded tests in test_shared_mutex.cpp cause non-atomic gcov
counters to overflow and go negative, making lcov fail with:

  geninfo: ERROR: Unexpected negative count for test_shared_mutex.cpp:128

Adding -fprofile-update=atomic ensures counter increments are atomic,
preventing wrap-around in concurrent test scenarios.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard

konard commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

🔄 Auto-restart-until-mergeable Log (iteration 1)

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $0.301865
  • Calculated by Anthropic: $0.582758 USD
  • Difference: $0.280894 (+93.05%)
    📎 Log file uploaded as Gist (4788KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard

konard commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@netkeep80
netkeep80 merged commit 64e7fa5 into netkeep80:main Mar 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants