pymembar 0.0.1__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pymembar might be problematic. Click here for more details.
membar/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Import the C extension module and expose its functions
|
|
2
|
+
try:
|
|
3
|
+
from ._membar import wmb, rmb, fence # Import from private C extension
|
|
4
|
+
__all__ = ['wmb', 'rmb', 'fence']
|
|
5
|
+
except ImportError as e:
|
|
6
|
+
# Fallback error message if the C extension cannot be imported
|
|
7
|
+
raise ImportError(f"Could not import C extension module: {e}")
|
|
8
|
+
|
|
9
|
+
# do NOT alter the following line in any way EXCEPT changing
|
|
10
|
+
# the version number. no comments, no rename, whatsoever
|
|
11
|
+
__version__ = "0.0.1"
|
|
Binary file
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pymembar
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Memory barrier utilities for Python - provides wmb, rmb, and fence operations
|
|
5
|
+
Author-email: fwkrumm <fwkrumm@github.com>
|
|
6
|
+
Maintainer-email: fwkrumm <fwkrumm@github.com>
|
|
7
|
+
Project-URL: Homepage, https://github.com/fwkrumm/pymembar
|
|
8
|
+
Project-URL: Repository, https://github.com/fwkrumm/pymembar
|
|
9
|
+
Project-URL: Issues, https://github.com/fwkrumm/pymembar/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/fwkrumm/pymembar/blob/master/README.md
|
|
11
|
+
Keywords: memory-barriers,concurrency,low-level,synchronization,threading
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Operating System :: MacOS
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: C
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Topic :: System :: Hardware
|
|
27
|
+
Classifier: Topic :: System :: Operating System
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: >=3.8
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE.txt
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# Python Memory Barrier (pymembar)
|
|
35
|
+
|
|
36
|
+
Memory barrier utilities for Python - provides low-level memory ordering primitives for concurrent programming. Usually you would not need this in Python due to GIL and generally strong memory ordering on x86/x86_64. However, on weakly-ordered architectures like ARM, memory barriers can be useful for ensuring correct visibility and ordering of memory operations when for example working with shared memory, named semaphores, or lock-free data structures.
|
|
37
|
+
|
|
38
|
+
I used AI (GitHub Copilot) to help generate parts of this README, documentation strings, and some configuration files. Please report any inaccuracies or errors you may find.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Overview
|
|
42
|
+
|
|
43
|
+
This package provides Python bindings for memory barrier operations, ensuring that memory operations are visible to other processes and threads in the correct order. Memory barriers do not provide synchronization themselves, but rather control the visibility and ordering of memory operations across CPU cores and processes.
|
|
44
|
+
|
|
45
|
+
The package includes three core functions:
|
|
46
|
+
|
|
47
|
+
- `wmb()` - Write memory barrier
|
|
48
|
+
- `rmb()` - Read memory barrier
|
|
49
|
+
- `fence()` - Full memory fence
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install pymembar
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import membar
|
|
61
|
+
|
|
62
|
+
# Write memory barrier - ensures all write operations before this point
|
|
63
|
+
# are visible to other processes/threads before any writes after this point
|
|
64
|
+
membar.wmb()
|
|
65
|
+
|
|
66
|
+
# Read memory barrier - ensures all read operations before this point
|
|
67
|
+
# complete before any read operations after this point
|
|
68
|
+
membar.rmb()
|
|
69
|
+
|
|
70
|
+
# Full memory fence - ensures all memory operations before this point
|
|
71
|
+
# are visible to other processes/threads before any operations after this point
|
|
72
|
+
membar.fence()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## When Are Memory Barriers Needed?
|
|
76
|
+
|
|
77
|
+
Memory barriers are primarily needed on weakly-ordered CPU architectures like ARM, where the processor may reorder memory operations for performance optimization. On x86/x86_64 architectures, the strong memory ordering model means that memory barriers are often not strictly necessary for most use cases, as the hardware already provides strong ordering guarantees.
|
|
78
|
+
|
|
79
|
+
However, memory barriers can still be useful on x86 in specific scenarios:
|
|
80
|
+
- When interfacing with memory-mapped I/O
|
|
81
|
+
- In lock-free programming with specific compiler optimizations
|
|
82
|
+
- When precise ordering is critical for correctness
|
|
83
|
+
|
|
84
|
+
**Note:** Most Python applications will not need memory barriers due to the Global Interpreter Lock (GIL) and Python's threading model.
|
|
85
|
+
|
|
86
|
+
## Requirements
|
|
87
|
+
|
|
88
|
+
- Python 3.8+
|
|
89
|
+
- Compatible with Windows, Linux, and macOS
|
|
90
|
+
|
|
91
|
+
## Contributing
|
|
92
|
+
|
|
93
|
+
I am not a C expert and would be happy to receive any constructive feedback, suggestions, or contributions to improve this library. Feel free to open issues or submit pull requests on the [GitHub repository](https://github.com/fwkrumm/pymembar).
|
|
94
|
+
|
|
95
|
+
## Disclaimer
|
|
96
|
+
|
|
97
|
+
Parts of the core code, this README, and documentation strings were generated with AI assistance.
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# TODOs
|
|
101
|
+
- Is it possible to write tests for the functionality
|
|
102
|
+
- Add ARM build to CI/CD pipeline as soon as they are available via GitHub Actions
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
membar/__init__.py,sha256=-Xm1ccC6hwimL_Z4DEGCka_yDAkWIiqedebyYpAmEkU,487
|
|
2
|
+
membar/_membar.cp312-win_amd64.pyd,sha256=mtjNJOc947ZLzH3X5uozgzqXW9ucgymGvMfS2Dkd3KQ,10752
|
|
3
|
+
pymembar-0.0.1.dist-info/licenses/LICENSE.txt,sha256=7EMH6cj__2wGBWdxHt8WcQlboBf5-C-Z84pZ4l0U4ds,1527
|
|
4
|
+
pymembar-0.0.1.dist-info/METADATA,sha256=MLi0LoLgILTughq4LB2q28EpjZ8S0_HedD64x7b3BzA,4674
|
|
5
|
+
pymembar-0.0.1.dist-info/WHEEL,sha256=8UP9x9puWI0P1V_d7K2oMTBqfeLNm21CTzZ_Ptr0NXU,101
|
|
6
|
+
pymembar-0.0.1.dist-info/top_level.txt,sha256=FTuLb28Ianih6q3VxqZmPeRo7ppIhVkSpLcVkbNrxow,7
|
|
7
|
+
pymembar-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024, Fabian Krumm
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
membar
|