• 2 Posts
  • 48 Comments
Joined 2 years ago
cake
Cake day: October 29th, 2024

help-circle

  • Perfect is really doing some heavy lifting. Sure shes better. I would have voted for her if i was an US-American. But shes still garbage. She kind of is controlled opposition. Making us look away from what would be actually good vs whats better than the worst option. It serves to legitimize their position in fear of the alternative. Thats not democracy. I am not saying that you should not vote, endorse or even accept the shitstain we get in the USA that is represented by Trump but running to the Democrats as the goal or seeing voting as the primary political action is a big blunder in my eyes. (again do vote).









  • For anyone interested, I did make a second version of the same logic. Even if i kind of had atomic operations in mind i did not know that i was thinking of atomic or what atomic was for that matter. So in a broad sense i assumed raw pointers were atomic. Also worth noting implementing a false Sync for &str seemed to be unnecessary to get it to run in the first example even if i got the impression during construction that it was. Just pretend in the first example “ExemptSyncStringSlice” is just &str if you want to compare them for some reason.

    I don’t know the overhead of AtomicPtr compared to raw pointers and it is dependent on operating systems that can use an atomic load store (whatever that means.) But this version seems more “correct” at least.

    use std::sync::atomic::{AtomicPtr, Ordering};
    use std::time::Duration;
    
    
    fn main()
    {
    	let pointer: AtomicPtr<&'static str> = AtomicPtr::new(&mut "Hello!");
    
    	let mut value2: &'static str = "Hi!"; // Place outside scope due to lifetime.
    
    	thread::scope(|scope|
    	{
    		scope.spawn
    		(|| {
    			for _ in 1..1000
    			{
    				unsafe { println!("String = {}",  *pointer.load(Ordering::Relaxed)); }
    			}
    		});
    
    		scope.spawn
    		(|| {
    			sleep(Duration::from_millis(1));
    			pointer.store(&mut value2, Ordering::Relaxed)
    		});
    	});
    }
    

    Thank you all who responded btw.