Skip to content

Commit

Permalink
FEARLESS CONCURRENCY
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotito committed Oct 3, 2023
1 parent eb8af46 commit 9f9c237
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/bin/gui.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
use std::thread;

use fpt::lr35902::LR35902;

use std::{
sync::{Arc, Mutex},
thread, time,
};

use winit::{
event::{Event, WindowEvent},
event_loop::EventLoop,
window::WindowBuilder,
};

fn main() {
let mut lr = LR35902::new();
let lr: Arc<Mutex<LR35902>> = Arc::new(Mutex::new(LR35902::new()));
let lr_for_the_thing: Arc<Mutex<LR35902>> = Arc::clone(&lr);

let the_thing = thread::spawn(move || loop {
lr.step();
let the_thing = thread::spawn(move || {
let mut loop_cycle: u64 = 0;
loop {
loop_cycle += 1;
println!("---[Loop cycle: {:#04}]---", loop_cycle);

lr_for_the_thing.lock().unwrap().step();

println!();
thread::sleep(time::Duration::from_millis(100));
}
});

the_loop();
the_loop(lr.clone());
the_thing.join().unwrap();
}

fn the_loop() {
fn the_loop(lr: Arc<Mutex<LR35902>>) {
let event_loop: EventLoop<()> = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();

Expand All @@ -34,7 +47,7 @@ fn the_loop() {
}
Event::MainEventsCleared => {
// Application update code.
// lr35902.step();
// lr.lock().unwrap().step();

// Queue a RedrawRequested event.
//
Expand Down

0 comments on commit 9f9c237

Please sign in to comment.