Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make guid() thread safe #12

Open
bvssvni opened this issue May 7, 2015 · 1 comment
Open

Make guid() thread safe #12

bvssvni opened this issue May 7, 2015 · 1 comment

Comments

@bvssvni
Copy link
Collaborator

bvssvni commented May 7, 2015

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
    }
}
@mitchmindtree
Copy link
Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants