Skip to content

Commit d288f4b

Browse files
committed
chore: added tests and FAQ in readme, also added macOS to test scenario
1 parent a27b01a commit d288f4b

File tree

4 files changed

+300
-18
lines changed

4 files changed

+300
-18
lines changed

.github/workflows/build_and_test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ jobs:
1010
runs-on: ${{ matrix.os }}
1111
strategy:
1212
matrix:
13-
os: [ubuntu-latest, windows-latest]
13+
os: [ubuntu-latest, macos-latest, windows-latest]
1414
build_type: [Release]
1515
include:
1616
- os: ubuntu-latest
1717
cc: gcc
1818
cxx: g++
19+
- os: macos-latest
20+
cc: clang
21+
cxx: clang++
1922
- os: windows-latest
2023
cc: cl
2124
cxx: cl
@@ -35,6 +38,8 @@ jobs:
3538

3639
- name: Test
3740
run: cmake --build build --config Release --target run_test
41+
env:
42+
LSM_NOFLAKE: 1
3843

3944
release:
4045
runs-on: ubuntu-latest

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111
- Makefile with `build`, `test`, `clean`, and `setup` targets wrapping CMake
1212
- Re-verified current macOS aarch64 (Apple Silicon) support on Sequoia 15.7.3
13-
- 6 new test cases: `Memory` accessors, `getWriteFlags` logic, `std::span` write overloads, segment overwrite, queue capacity=1 edge case, `maxMessageSize` boundary
13+
- New test case on `Memory` accessors, `getWriteFlags` logic, `std::span` write overloads, segment overwrite, queue capacity=1 edge case, `maxMessageSize` boundary and concurrent writing; also added docs to understand the tests better
1414
- `.vscode/c_cpp_properties.json` for C++20 IntelliSense on macOS (arm64/aarch64)
15+
- No-flake stability test: re-runs the full suite 1000 times as subprocesses to catch timing-dependent failures (cross-platform, skips itself via `LSM_NOFLAKE` env var)
16+
- Added `macos-latest` to GitHub Actions CI matrix with `LSM_NOFLAKE=1` to skip the 1000-iteration flake test in CI
1517

1618
### Changed
1719
- Improved README: added supported platforms table, building instructions, tightened examples and documentation

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# libsharedmemory
22

3-
A lightweight, header-only C++20 library for inter-process communication via shared memory. Transfer data between isolated OS processes or between modules written in different programming languages with a simple, cross-platform API.
3+
A lightweight, header-only C++20 library for inter-process communication via shared memory. Transfer data between isolated OS processes - or between modules written in different programming languages - with a simple, cross-platform API.
44

55
**Key capabilities:**
66
- Stream-based read/write transfer (`std::string`, `float*`, `double*`, scalars)
@@ -51,7 +51,7 @@ writer.write(data);
5151
std::string result = reader.readString();
5252
```
5353
54-
### Message Queue
54+
### Message Queue (C++20)
5555
5656
```cpp
5757
SharedMemoryQueue writer{"queue", /*capacity*/ 10, /*maxMessageSize*/ 256, /*persistent*/ true, /*isWriter*/ true};
@@ -88,7 +88,7 @@ std::cout << "Size: " << reader.size() << ", Empty: " << reader.isEmpty() << std
8888

8989
## Installation
9090

91-
Copy `include/libsharedmemory/libsharedmemory.hpp` into your project's include path it's a single header.
91+
Copy `include/libsharedmemory/libsharedmemory.hpp` into your project's include path - it's a single header.
9292

9393
Alternatively, use `npm` for dependency management:
9494

@@ -121,11 +121,24 @@ enum DataType {
121121

122122
`kMemoryChanged` flips odd/even to signal data changes, allowing continuous readers to detect every update.
123123

124-
## Limits
124+
## Limits and Frequently Asked Questions
125+
126+
### Can I use this for cross-platform network communication?
127+
128+
No. **Endianness** is not handled. This is fine for local shared memory but requires attention if copying buffers to a network protocol.
129+
130+
### What about cross compiler compatibility?
131+
132+
**Cross-compiler** behavior for the binary memory layout is undefined. The library is designed for C++20 compliant compilers on the same platform. For cross-compiler or cross-language interoperability, you must ensure consistent data type sizes, alignment, and endianness.
133+
134+
### Can I use this with multiple writers?
135+
136+
Maybe for slow writers, **if you are lucky**.
137+
**Concurrent writers**(`SharedMemoryWriteStream`) are currently not safely supported. `write()` performs 3 non-atomic `memcpy` calls (flags, size, data). Two threads writing to the same segment can interleave these operations, producing torn reads with mixed content or incorrect sizes. Use a single writer per segment or add external synchronization.
138+
139+
### Are multiple producers supported for `SharedMemoryQueue`?
125140

126-
- **Endianness** is not handled. This is fine for local shared memory but requires attention if copying buffers to a network protocol.
127-
- **Cross-compiler** behavior for the binary memory layout is undefined.
128-
- **SharedMemoryQueue** works best with a single producer. Multiple concurrent producers require external synchronization.
141+
Not yet. `enqueue()` uses a non-atomic read-modify-write on the write index. Two threads calling `enqueue()` on the same queue will read the same slot index, overwrite each other's data, and advance the index only once - causing **message corruption** in testing (up to 45% on macOS 15.7, aarch64, Macbook Air M4, 1000 messages, 2 producers). Use a single producer per queue or add a mutex around `enqueue()`.
129142

130143
## Roadmap
131144

@@ -134,4 +147,4 @@ enum DataType {
134147

135148
## License
136149

137-
MIT see [LICENSE](LICENSE).
150+
MIT - see [LICENSE](LICENSE).

0 commit comments

Comments
 (0)