FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-159462: Relax the thread check in _PyMem_mi_page_reclaimed() by corona10 · Pull Request #159807 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 14 additions & 0 deletions Lib/test/test_free_threading/test_interpreters.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import textwrap
import unittest

from test import support
from test.support import import_helper, script_helper


Expand All @@ -24,6 +25,19 @@ def test_destroy_subinterpreter_does_not_abort(self):
""")
script_helper.assert_python_ok('-c', script)

@support.requires_resource('cpu')
def test_destroy_subinterpreter_with_abandoned_pages_does_not_abort(self):
# gh-159462: Py_EndInterpreter() clears a non-current thread state.
script = textwrap.dedent("""
import _testinternalcapi

interpid = _testinternalcapi.create_interpreter()
_testinternalcapi.exec_interpreter(
interpid, "objs = [[i] for i in range(400_000)]; del objs")
_testinternalcapi.destroy_interpreter(interpid, basic=True)
""")
script_helper.assert_python_ok('-c', script)


if __name__ == "__main__":
unittest.main()
5 changes: 4 additions & 1 deletion Objects/obmalloc.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ _PyMem_mi_page_reclaimed(mi_page_t *page)
if (mi_page_all_free(page)) {
assert(page->qsbr_node.next == NULL);
_PyThreadStateImpl *tstate = tstate_from_heap(mi_page_heap(page));
assert(tstate == (_PyThreadStateImpl *)_PyThreadState_GET());
// gh-159462: the owning tstate may differ from the current
// one, but the heap is always owned by the current OS thread,
// so the page list is not shared with other OS threads.
assert(mi_page_heap(page)->thread_id == _Py_ThreadId());
page->retire_expire = 0;
llist_insert_tail(&tstate->mimalloc.page_list, &page->qsbr_node);
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL