|
4 | 4 | #[cfg(test)]
|
5 | 5 | mod tests {
|
6 | 6 | use crate::*;
|
| 7 | + #[cfg(feature = "sync")] |
| 8 | + use std::thread; |
7 | 9 |
|
8 | 10 | #[test]
|
9 | 11 | fn test_int() {
|
@@ -40,22 +42,22 @@ mod tests {
|
40 | 42 | let b_copy_3 = b.clone();
|
41 | 43 | let a_copy_4 = a.clone();
|
42 | 44 | let b_copy_4 = b.clone();
|
43 |
| - let handle_ab = std::thread::spawn(move || { |
| 45 | + let handle_ab = thread::spawn(move || { |
44 | 46 | let a_plus_b = a_copy_1.concat(&b_copy_1);
|
45 | 47 | let a_plus_b_vec = a_plus_b.to_array();
|
46 | 48 | a_plus_b_vec
|
47 | 49 | });
|
48 |
| - let handle_ba = std::thread::spawn(move || { |
| 50 | + let handle_ba = thread::spawn(move || { |
49 | 51 | let b_plus_a = b_copy_2.concat(&a_copy_2);
|
50 | 52 | let b_plus_a_vec = b_plus_a.to_array();
|
51 | 53 | b_plus_a_vec
|
52 | 54 | });
|
53 |
| - let handle_ab_2 = std::thread::spawn(move || { |
| 55 | + let handle_ab_2 = thread::spawn(move || { |
54 | 56 | let a_plus_b = a_copy_3.concat(&b_copy_3);
|
55 | 57 | let a_plus_b_vec = a_plus_b.to_array();
|
56 | 58 | a_plus_b_vec
|
57 | 59 | });
|
58 |
| - let handle_ba_2 = std::thread::spawn(move || { |
| 60 | + let handle_ba_2 = thread::spawn(move || { |
59 | 61 | let b_plus_a = b_copy_4.concat(&a_copy_4);
|
60 | 62 | let b_plus_a_vec = b_plus_a.to_array();
|
61 | 63 | b_plus_a_vec
|
@@ -1293,9 +1295,30 @@ mod tests {
|
1293 | 1295 | let c3 = c;
|
1294 | 1296 | assert_eq!(c3, c2);
|
1295 | 1297 | }
|
1296 |
| - /*impl GeneralTrait for Rc<ADatatype> { |
1297 |
| - fn _clone(&self) -> Box<dyn GeneralTrait> { |
1298 |
| - Box::new(self.as_ref().clone()) |
| 1298 | + |
| 1299 | + #[cfg(feature = "sync")] |
| 1300 | + #[test] |
| 1301 | + fn test_object_share_async() { |
| 1302 | + let obj = ClassWrapper::constructor_object(53); |
| 1303 | + let objClone = obj.clone(); |
| 1304 | + |
| 1305 | + let handle: thread::JoinHandle<i32> = thread::spawn(move || { |
| 1306 | + // Thread code here |
| 1307 | + let mut result: *const ClassWrapper<i32> = objClone.as_ref(); |
| 1308 | + for _i in 0..10000 { |
| 1309 | + let obj2 = Object::from_ref(objClone.as_ref()); |
| 1310 | + result = obj2.as_ref() as *const ClassWrapper<i32>; |
| 1311 | + } |
| 1312 | + result as i32 |
| 1313 | + }); |
| 1314 | + let mut result: *const ClassWrapper<i32> = obj.as_ref(); |
| 1315 | + for _i in 0..10000 { |
| 1316 | + let obj2 = Object::from_ref(obj.as_ref()); |
| 1317 | + result = obj2.as_ref() as *const ClassWrapper<i32>; |
1299 | 1318 | }
|
1300 |
| - }*/ |
| 1319 | + |
| 1320 | + // Wait for thread to finish |
| 1321 | + assert_eq!(handle.join().unwrap(), result as i32); |
| 1322 | + assert_eq!(result as i32, obj.as_ref() as *const ClassWrapper<i32> as i32); |
| 1323 | + } |
1301 | 1324 | }
|
0 commit comments