elmesque icon indicating copy to clipboard operation
elmesque copied to clipboard

Make `guid()` thread safe

Open bvssvni opened this issue 10 years ago • 1 comments

Currently it mutates a static variable:

/// The global graphics unique identifier counter.
pub type Guid = u64;
pub static mut GUID: Guid = 0;


/// Increment the GUID and return the new GUID.
fn guid() -> Guid {
    unsafe {
        GUID += 1; // <--- two threads can increment this at once
        GUID // <--- the two threads receive the same id
    }
}

bvssvni avatar May 07 '15 16:05 bvssvni

@bvssvni indeed, however I don't even think the Guid is even being used by anything (Element stores one, however I don't think it is ever used). We could probably just get rid of it.

mitchmindtree avatar May 07 '15 16:05 mitchmindtree