mirror of
https://github.com/Dummi26/mers.git
synced 2025-12-16 20:17:50 +01:00
Add lock_update function for safer multithreading
&v = (v, 1).sum might fail if two threads do it at the same time or something, so you can now lock the reference to ensure no other thread messes with your data while you update its value
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use crate::data::{self, Data, Type};
|
||||
|
||||
@@ -40,7 +40,7 @@ impl MersStatement for Variable {
|
||||
}
|
||||
fn run_custom(&self, info: &mut super::Info) -> Data {
|
||||
if self.is_init {
|
||||
let nothing = Arc::new(Mutex::new(Data::new(data::bool::Bool(false))));
|
||||
let nothing = Arc::new(RwLock::new(Data::new(data::bool::Bool(false))));
|
||||
while info.scopes[self.var.0].vars.len() <= self.var.1 {
|
||||
info.scopes[self.var.0].vars.push(Arc::clone(¬hing));
|
||||
}
|
||||
@@ -52,7 +52,7 @@ impl MersStatement for Variable {
|
||||
)))
|
||||
} else {
|
||||
info.scopes[self.var.0].vars[self.var.1]
|
||||
.lock()
|
||||
.write()
|
||||
.unwrap()
|
||||
.clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user