Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit87d7a19

Browse files
[3.14]gh-133980: use atomic store inPyObject_GenericSetDict (GH-133988) (#134354)
gh-133980: use atomic store in `PyObject_GenericSetDict` (GH-133988)(cherry picked from commitec39fd2)Co-authored-by: Kumar Aditya <kumaraditya@python.org>
1 parentb0bf48a commit87d7a19

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

‎Lib/test/test_free_threading/test_dict.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ def reader_func():
228228

229229
self.assertEqual(count,0)
230230

231+
deftest_racing_object_get_set_dict(self):
232+
e=Exception()
233+
234+
defwriter():
235+
foriinrange(10000):
236+
e.__dict__= {1:2}
237+
238+
defreader():
239+
foriinrange(10000):
240+
e.__dict__
241+
242+
t1=Thread(target=writer)
243+
t2=Thread(target=reader)
244+
245+
withthreading_helper.start_threads([t1,t2]):
246+
pass
231247

232248
if__name__=="__main__":
233249
unittest.main()

‎Objects/object.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,13 @@ PyObject_GenericSetDict(PyObject *obj, PyObject *value, void *context)
19311931
return-1;
19321932
}
19331933
Py_BEGIN_CRITICAL_SECTION(obj);
1934-
Py_XSETREF(*dictptr,Py_NewRef(value));
1934+
PyObject*olddict=*dictptr;
1935+
FT_ATOMIC_STORE_PTR_RELEASE(*dictptr,Py_NewRef(value));
1936+
#ifdefPy_GIL_DISABLED
1937+
_PyObject_XDecRefDelayed(olddict);
1938+
#else
1939+
Py_XDECREF(olddict);
1940+
#endif
19351941
Py_END_CRITICAL_SECTION();
19361942
return0;
19371943
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp