IronLanguages / IronLanguages/ironpython3
GC thread not synchronized with main thread when acessing shared variables
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.8k
- Forks
- 316
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 1
Description
This is from test_scope.ScopeTests('testLeaks') in StdLib:
class Foo:
count = 0
def __init__(self):
Foo.count += 1
def __del__(self):
Foo.count -= 1
def f1():
x = Foo()
def f2():
return x
f2()
for i in range(100):
f1()
assert Foo.count == 0
Even with adding gc.collect(), Foo.count is not always 0 (it may be off by a small number in either direction). I could never reproduce it when running such a simple case standalone, but it happens occasionally when the whole test suite is run (with parallel jobs enabled).
I suspect the problem is because __init__ and __del__ are being run on different threads but both update a shared variable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the StdLib test_scope.ScopeTests('testLeaks') case and reproduce it with gc.collect() while the whole suite runs with parallel jobs enabled. Investigate the differing-thread updates from Foo.init and Foo.del; done means the test consistently reaches Foo.count == 0 without parallel-run failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, python
- Domain
- backend, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100