8000 gh-128942: make arraymodule.c free-thread safe (lock-free) by tom-pytel · Pull Request #130771 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-128942: make arraymodule.c free-thread safe (lock-free) #130771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
8000 Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f54c5fc
slow arraymodule
tom-pytel Mar 1, 2025
4c71f00
lockfree read and write single element
tom-pytel Mar 2, 2025
512c4c7
📜🤖 Added by blurb_it.
blurb-it[bot] Mar 2, 2025
060100f
ensure_shared_on_resize() in one more place
tom-pytel Mar 2, 2025
d0b17c6
fix stupid direct return out of critical section
tom-pytel Mar 3, 2025
c17b787
requested changes
tom-pytel Mar 3, 2025
4fd8383
downgrade to _Py_atomic_load_ptr_relaxed in missed place
tom-pytel Mar 3, 2025
d00f2b7
arraymodule linked statically
tom-pytel Mar 4, 2025
a3e6004
cleanups
tom-pytel Mar 5, 2025
fb6212a
test and tsan stuff
tom-pytel Mar 5, 2025
04a8f9d
getters and setters using atomics
tom-pytel Mar 5, 2025
01423fd
fix 2 byte wchar_t
tom-pytel Mar 6, 2025
99331dd
remove debug printf
tom-pytel Mar 6, 2025
07c98cc
just a hunch...
tom-pytel Mar 6, 2025
cf3bbbb
atomic "memcpy"
tom-pytel Mar 6, 2025
51135a4
misc
tom-pytel Mar 7, 2025
fff827e
use proper type FT_ macros
tom-pytel Mar 8, 2025
12f0ff6
atomic aggregate _Py_atomic_source_memcpy_relaxed()
tom-pytel Mar 10, 2025
1a6b8df
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel Mar 11, 2025
94ef417
remove atomic memcpy
tom-pytel Mar 11, 2025
0056412
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel Mar 11, 2025
1431784
regen clinic
tom-pytel Mar 11, 2025
460d3d7
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel Mar 11, 2025
409239c
requested changes
tom-pytel Mar 15, 2025
a6f17c9
more requested changes
tom-pytel Mar 17, 2025
b5d219e
__declspec(align(8)) for Windows
tom-pytel Mar 17, 2025
2c82071
shut up check-c-globals
tom-pytel Mar 17, 2025
1ba50e9
alignment changes
tom-pytel Mar 20, 2025
576aebf
MS_WINDOWS -> _MSC_VER
tom-pytel Mar 20, 2025
4dd0954
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel Mar 20, 2025
d4e5313
#include "pycore_gc.h", something moved
tom-pytel Mar 20, 2025
48eabe3
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel Mar 25, 2025
c056b13
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel Mar 25, 2025
affae8e
remove NULL check in arraydata_free()
tom-pytel Mar 25, 2025
689c7a3
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel Mar 31, 2025
3e2f8cd
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel Apr 4, 2025
7286fed
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel Apr 14, 2025
6550906
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel Apr 23, 2025
5b35203
Merge branch 'main' into fix-issue-128942-lockfree 8000
tom-pytel May 2, 2025
15d92ca
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel May 5, 2025
2e7132e
change to use new _Py_ALIGN_AS() macro
tom-pytel May 5, 2025
06f86cf
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel May 8, 2025
d29c208
Merge branch 'main' into fix-issue-128942-lockfree
tom-pytel May 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use proper type FT_ macros
  • Loading branch information
tom-pytel committed Mar 8, 2025
commit fff827e0525e7f9cd3d414ed8cd848e0283795f2
2 changes: 2 additions & 0 deletions Lib/test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,8 @@ def iter_reduce(b, a, it):
self.check([clear] + [iter_next] * 10, a := array.array('i', [1] * 10), iter(a))

@unittest.skipUnless(support.check_sanitizer(thread=True), 'meant for tsan')
@threading_helper.reap_threads
@threading_helper.requires_working_threading()
def test_free_threading_tsan(self):
def copy_back_and_forth(b, a, count):
b.wait()
Expand Down
20 changes: 10 additions & 10 deletions Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static PyObject *
BB_getitem(char *items, Py_ssize_t i)
{
return PyLong_FromLong(
(long) (unsigned char) FT_ATOMIC_LOAD_CHAR_RELAXED(items[i]));
(long) FT_ATOMIC_LOAD_UCHAR_RELAXED(((unsigned char *) items)[i]));
}

static int
Expand All @@ -409,7 +409,7 @@ BB_setitem(char *items, Py_ssize_t i, PyObject *v)
return -1;
}
if (i >= 0) {
FT_ATOMIC_STORE_CHAR_RELAXED(items[i], x);
FT_ATOMIC_STORE_UCHAR_RELAXED(((unsigned char *) items)[i], x);
}
return 0;
}
Expand Down Expand Up @@ -525,7 +525,7 @@ static PyObject *
HH_getitem(char *items, Py_ssize_t i)
{
return PyLong_FromLong(
(long) (unsigned short) FT_ATOMIC_LOAD_SHORT_RELAXED(((short *) items)[i]));
(long) FT_ATOMIC_LOAD_USHORT_RELAXED(((unsigned short *) items)[i]));
}

static int
Expand All @@ -548,7 +548,7 @@ HH_setitem(char *items, Py_ssize_t i, PyObject *v)
return -1;
}
if (i >= 0) {
FT_ATOMIC_STORE_SHORT_RELAXED(((short *) items)[i], (unsigned short) x);
FT_ATOMIC_STORE_USHORT_RELAXED(((unsigned short *) items)[i], (unsigned short) x);
}
return 0;
}
Expand Down Expand Up @@ -578,7 +578,7 @@ static PyObject *
II_getitem(char *items, Py_ssize_t i)
{
return PyLong_FromUnsignedLong(
(unsigned long) (unsigned int) FT_ATOMIC_LOAD_INT_RELAXED(((int *) items)[i]));
(unsigned long) FT_ATOMIC_LOAD_UINT_RELAXED(((unsigned int *) items)[i]));
}

static int
Expand Down Expand Up @@ -610,7 +610,7 @@ II_setitem(char *items, Py_ssize_t i, PyObject *v)
return -1;
}
if (i >= 0) {
FT_ATOMIC_STORE_INT_RELAXED(((int *) items)[i], (unsigned int) x);
FT_ATOMIC_STORE_UINT_RELAXED(((unsigned int *) items)[i], (unsigned int) x);
}

if (do_decref) {
Expand Down Expand Up @@ -643,7 +643,7 @@ static PyObject *
LL_getitem(char *items, Py_ssize_t i)
{
return PyLong_FromUnsignedLong(
(unsigned long) FT_ATOMIC_LOAD_LONG_RELAXED(((long *) items)[i]));
FT_ATOMIC_LOAD_ULONG_RELAXED(((unsigned long *) items)[i]));
}

static int
Expand All @@ -667,7 +667,7 @@ LL_setitem(char *items, Py_ssize_t i, PyObject *v)
return -1;
}
if (i >= 0) {
FT_ATOMIC_STORE_LONG_RELAXED(((long *) items)[i], x);
FT_ATOMIC_STORE_ULONG_RELAXED(((unsigned long *) items)[i], x);
}

if (do_decref) {
Expand Down Expand Up @@ -700,7 +700,7 @@ static PyObject *
QQ_getitem(char *items, Py_ssize_t i)
{
return PyLong_FromUnsignedLongLong(
(unsigned long long) FT_ATOMIC_LOAD_LLONG_RELAXED(((long long *) items)[i]));
FT_ATOMIC_LOAD_ULLONG_RELAXED(((unsigned long long *) items)[i]));
}

static int
Expand All @@ -724,7 +724,7 @@ QQ_setitem(char *items, Py_ssize_t i, PyObject *v)
return -1;
}
if (i >= 0) {
FT_ATOMIC_STORE_LLONG_RELAXED(((long long *) items)[i], x);
FT_ATOMIC_STORE_ULLONG_RELAXED(((unsigned long long *) items)[i], x);
}

if (do_decref) {
Expand Down
Loading
0