FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
d-mercator/python/pybind11/tests/test_thread.cpp at main · networkgeometry/d-mercator · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
networkgeometry
/
d-mercator
Public
Notifications
You must be signed in to change notification settings
Fork
8
Star
23
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
d-mercator
/
python
/
pybind11
/
tests
/
test_thread.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (49 loc) · 1.81 KB
Breadcrumbs
d-mercator
/
python
/
pybind11
/
tests
/
test_thread.cpp
Copy path
File metadata and controls
66 lines (49 loc) · 1.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
tests/test_thread.cpp -- call pybind11 bound methods in threads
Copyright (c) 2021 Laramie Leavitt (Google LLC) <lar@google.com>
All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
*/
#
include
<
pybind11/cast.h
>
#
include
<
pybind11/pybind11.h
>
#
include
"
pybind11_tests.h
"
#
include
<
chrono
>
#
include
<
thread
>
namespace
py
=
pybind11;
namespace
{
struct
IntStruct
{
explicit
IntStruct
(
int
v) : value(v){};
~IntStruct
() { value = -value; }
IntStruct
(
const
IntStruct &) =
default
;
IntStruct &
operator
=(
const
IntStruct &) =
default
;
int
value;
};
}
//
namespace
TEST_SUBMODULE
(thread, m) {
py::class_<IntStruct>(m,
"
IntStruct
"
).
def
(
py::init
([](
const
int
i) {
return
IntStruct
(i); }));
//
implicitly_convertible uses loader_life_support when an implicit
//
conversion is required in order to lifetime extend the reference.
//
//
This test should be run with ASAN for better effectiveness.
py::implicitly_convertible<
int
, IntStruct>();
m.
def
(
"
test
"
, [](
int
expected,
const
IntStruct &in) {
{
py::gil_scoped_release release;
std::this_thread::sleep_for
(
std::chrono::milliseconds
(
5
));
}
if
(in.
value
!= expected) {
throw
std::runtime_error
(
"
Value changed!!
"
);
}
});
m.
def
(
"
test_no_gil
"
,
[](
int
expected,
const
IntStruct &in) {
std::this_thread::sleep_for
(
std::chrono::milliseconds
(
5
));
if
(in.
value
!= expected) {
throw
std::runtime_error
(
"
Value changed!!
"
);
}
},
py::call_guard<py::gil_scoped_release>());
//
NOTE: std::string_view also uses loader_life_support to ensure that
//
the string contents remain alive, but that's a C++ 17 feature.
}
Back
|
FazBrowse Home
|
New Git URL