File tree Expand file tree Collapse file tree 3 files changed +38
-2
lines changed
src/hyperlight_host/examples Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -89,17 +89,29 @@ fn main() -> Result<()> {
89
89
let no_op = Noop :: < UninitializedSandbox , MultiUseSandbox > :: default ( ) ;
90
90
91
91
let mut multiuse_sandbox = usandbox. evolve ( no_op) ?;
92
+ let interrupt_handle = multiuse_sandbox. interrupt_handle ( ) ;
93
+
94
+ const NUM_CALLS : i32 = 5 ;
95
+ let thread = std:: thread:: spawn ( move || {
96
+ for _ in 0 ..NUM_CALLS {
97
+ // Sleep for a short time to allow the guest function to run.
98
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 500 ) ) ;
99
+ // Cancel the host function call.
100
+ interrupt_handle. kill ( ) ;
101
+ }
102
+ } ) ;
92
103
93
104
// Call a function that gets cancelled by the host function 5 times to generate some log entries.
94
105
95
- for _ in 0 ..5 {
106
+ for _ in 0 ..NUM_CALLS {
96
107
let mut ctx = multiuse_sandbox. new_call_context ( ) ;
97
108
98
109
let result = ctx. call ( "Spin" , ReturnType :: Void , None ) ;
99
110
assert ! ( result. is_err( ) ) ;
100
111
let result = ctx. finish ( ) ;
101
112
multiuse_sandbox = result. unwrap ( ) ;
102
113
}
114
+ thread. join ( ) . unwrap ( ) ;
103
115
104
116
Ok ( ( ) )
105
117
}
Original file line number Diff line number Diff line change @@ -102,10 +102,22 @@ fn do_hyperlight_stuff() {
102
102
let no_op = Noop :: < UninitializedSandbox , MultiUseSandbox > :: default ( ) ;
103
103
104
104
let mut multiuse_sandbox = usandbox. evolve ( no_op) . expect ( "Failed to evolve sandbox" ) ;
105
+ let interrupt_handle = multiuse_sandbox. interrupt_handle ( ) ;
106
+
107
+ const NUM_CALLS : i32 = 5 ;
108
+
109
+ let thread = std:: thread:: spawn ( move || {
110
+ for _ in 0 ..NUM_CALLS {
111
+ // Sleep for a short time to allow the guest function to run.
112
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 500 ) ) ;
113
+ // Cancel the host function call.
114
+ interrupt_handle. kill ( ) ;
115
+ }
116
+ } ) ;
105
117
106
118
// Call a function that gets cancelled by the host function 5 times to generate some metrics.
107
119
108
- for _ in 0 ..5 {
120
+ for _ in 0 ..NUM_CALLS {
109
121
let mut ctx = multiuse_sandbox. new_call_context ( ) ;
110
122
111
123
let result = ctx. call ( "Spin" , ReturnType :: Void , None ) ;
@@ -119,6 +131,7 @@ fn do_hyperlight_stuff() {
119
131
let result = join_handle. join ( ) ;
120
132
assert ! ( result. is_ok( ) ) ;
121
133
}
134
+ thread. join ( ) . unwrap ( ) ;
122
135
}
123
136
124
137
fn fn_writer ( _msg : String ) -> Result < i32 > {
Original file line number Diff line number Diff line change @@ -117,8 +117,18 @@ fn run_example() -> Result<()> {
117
117
let no_op = Noop :: < UninitializedSandbox , MultiUseSandbox > :: default ( ) ;
118
118
119
119
let mut multiuse_sandbox = usandbox. evolve ( no_op) ?;
120
+ let interrupt_handle = multiuse_sandbox. interrupt_handle ( ) ;
120
121
121
122
// Call a function that gets cancelled by the host function 5 times to generate some log entries.
123
+ const NUM_CALLS : i32 = 5 ;
124
+ let thread = std:: thread:: spawn ( move || {
125
+ for _ in 0 ..NUM_CALLS {
126
+ // Sleep for a short time to allow the guest function to run.
127
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 500 ) ) ;
128
+ // Cancel the host function call.
129
+ interrupt_handle. kill ( ) ;
130
+ }
131
+ } ) ;
122
132
123
133
for i in 0 ..5 {
124
134
let id = Uuid :: new_v4 ( ) ;
@@ -143,6 +153,7 @@ fn run_example() -> Result<()> {
143
153
let result = join_handle. join ( ) ;
144
154
assert ! ( result. is_ok( ) ) ;
145
155
}
156
+ thread. join ( ) . unwrap ( ) ;
146
157
147
158
Ok ( ( ) )
148
159
}
You can’t perform that action at this time.
0 commit comments