File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,11 @@ class BoolWrapper {
4141
4242#if defined(PYBIND11_HAS_BARRIER)
4343
44+ // Modifying the C/C++ members of a Python object from multiple threads requires a critical section
45+ // to ensure thread safety and data integrity.
46+ // These tests use a scoped critical section to ensure that the Python object is accessed in a
47+ // thread-safe manner.
48+
4449void test_scoped_critical_section (const py::handle &cls) {
4550 auto barrier = std::barrier (2 );
4651 auto bool_wrapper = cls (false );
@@ -113,7 +118,7 @@ void test_scoped_critical_section2(const py::handle &cls) {
113118 // Enter the critical section with two different objects.
114119 // This will ensure that the critical section is locked for both objects.
115120 py::scoped_critical_section lock{bool_wrapper1, bool_wrapper2};
116- // At this point, objects is locked by this thread via the scoped_critical_section.
121+ // At this point, objects are locked by this thread via the scoped_critical_section.
117122 // This barrier will ensure that other threads wait until this thread has released
118123 // the critical section before proceeding.
119124 barrier.arrive_and_wait ();
You can’t perform that action at this time.
0 commit comments