File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,12 @@ add_project_arguments(
7878 language : ' cython'
7979)
8080
81+ # Enable free-threading if Cython is new enough:
82+ #cy = meson.get_compiler('cython')
83+ #if cy.version().version_compare('>=3.1.0')
84+ # add_project_arguments('-Xfreethreading_compatible=true', language : 'cython')
85+ #endif
86+
8187if get_option (' coverage' )
8288 add_project_arguments (' -X' , ' linetrace=True' , language : ' cython' )
8389 add_project_arguments (' -DCYTHON_TRACE=1' , language : ' c' )
Original file line number Diff line number Diff line change 44import pickle
55import doctest
66import platform
7+ import random
8+ from threading import Thread
79
810from flint .utils .flint_exceptions import DomainError , IncompatibleContextError
911
@@ -1615,6 +1617,35 @@ def test_pickling():
16151617 obj2 = pickle .loads (s )
16161618 assert obj == obj2
16171619
1620+ def test_python_threads ():
1621+ iterations = 10 ** 5
1622+ threads = 3 + 1
1623+ size = 3
1624+ M = flint .fmpz_mat ([[0 ]* size for _ in range (size )])
1625+
1626+ def set_values ():
1627+ for i in range (iterations // 5 ):
1628+ i = random .randrange (M .nrows ())
1629+ j = random .randrange (M .ncols ())
1630+ if random .uniform (0 , 1 ) > 0.5 :
1631+ # Bigger than 2**62:
1632+ M [i ,j ] = 10 ** 128
1633+ else :
1634+ # Smaller than 2**62:
1635+ M [i ,j ] = 0
1636+
1637+ def get_dets ():
1638+ for i in range (iterations ):
1639+ M .det ()
1640+
1641+ threads = [Thread (target = set_values ) for _ in range (threads - 1 )]
1642+ threads .append (Thread (target = get_dets ))
1643+
1644+ for t in threads :
1645+ t .start ()
1646+ for t in threads :
1647+ t .join ()
1648+
16181649def test_fmpz_mod ():
16191650 from flint import fmpz_mod_ctx , fmpz , fmpz_mod
16201651
@@ -4586,6 +4617,7 @@ def test_all_tests():
45864617 test_arb ,
45874618
45884619 test_pickling ,
4620+ test_python_threads ,
45894621
45904622 test_all_tests ,
45914623]
You can’t perform that action at this time.
0 commit comments