NOTE: This is an experiment with 100% AI Generated code with human provided prompts, command. The component was generated using following command: "Follow instructions in generate-cpp-component.prompt.md. a lock free stack in C++ "
A modern C++ lock-free stack implementation following C++20/23 standards.
- 🔒 Lock-Free: Thread-safe operations without mutex locks
- ⚡ High Performance: CAS-based algorithm with minimal contention
- 🛡️ Memory Safe: Hazard pointers for safe memory reclamation
- 🎯 Modern C++: Uses C++20 features (concepts, requires clauses)
- 📦 Easy Integration: CMake, Conan, and vcpkg support
- ✅ Well Tested: Comprehensive unit and concurrent tests
- 📚 Documented: Full Doxygen API documentation
- C++20 compatible compiler (GCC 10+, Clang 11+, MSVC 2019+)
- CMake 3.21 or higher
- (Optional) Ninja build system
- (Optional) Conan or vcpkg for dependency management
# Clone the repository
git clone https://github.com/yourusername/stack_utils.git
cd stack_utils
# Configure and build
cmake --preset debug
cmake --build --preset debug
# Run tests
ctest --preset debug# Build everything
make build
# Run tests
make test
# Run examples
make examples
# Install
sudo make install# Install dependencies
conan install . --build=missing
# Build
conan build .#include <stack_utils/LockFreeStack.hpp>
#include <thread>
#include <iostream>
using namespace concurrent_containers;
int main() {
LockFreeStack<int> stack;
// Producer thread
std::thread producer([&stack]() {
for (int i = 0; i < 100; ++i) {
stack.push(i);
}
});
// Consumer thread
std::thread consumer([&stack]() {
int count = 0;
while (count < 100) {
if (auto value = stack.pop()) {
std::cout << "Popped: " << *value << std::endl;
++count;
}
}
});
producer.join();
consumer.join();
return 0;
}add_subdirectory(stack_utils)
target_link_libraries(your_target PRIVATE stack_utils::stack_utils)find_package(stack_utils REQUIRED)
target_link_libraries(your_target PRIVATE stack_utils::stack_utils)| Option | Default | Description |
|---|---|---|
STACK_UTILS_BUILD_TESTS |
ON | Build unit tests |
STACK_UTILS_BUILD_BENCHMARKS |
OFF | Build benchmarks |
STACK_UTILS_BUILD_EXAMPLES |
ON | Build examples |
STACK_UTILS_INSTALL |
ON | Generate install target |
Generate Doxygen documentation:
make docs
# Open docs/html/index.htmlLock-free operations with O(1) complexity:
- Push: ~20-50ns per operation
- Pop: ~30-60ns per operation
- Scales linearly with thread count
# Run all tests
make test
# Run with verbose output
ctest --preset debug --output-on-failure --verbose# Build and run benchmarks
make benchmarkContributions welcome! Please:
- Fork the repository
- Create a feature branch
- Follow the code style (run
make format) - Add tests for new features
- Submit a pull request
MIT License - see LICENSE file for details
DINHDUY TRAN (dinhduy.tran@live.com) & VS Code GitHub Copilot & Claude Sonnet 4.5 &