matklad / once_cell

Rust library for single assignment cells and lazy statics without macros
Apache License 2.0
1.84k stars 110 forks source link

impl Clone for OnceCell<T> #5

Closed matklad closed 6 years ago

matklad commented 6 years ago

Closes https://github.com/matklad/once_cell/issues/4

@starkat99 one thing I am worried about that there's no strong semantics here. What happens if one thread is calling get_or_init, and the over thread is calling .clone is indeterminate: you might get either an empty or a full cell. I think that's the reason why synch primitives like Once or Mutex don't implement Clone in general? Will this semantics work for you?

starkat99 commented 6 years ago

Oh sorry, I should have been more specific, I didn't realize the sync version was the same name. I agree, semantics are very unclear for sync version, so maybe don't need to do that? I was just needing single thread version to be clone.

matklad commented 6 years ago

unsync case is totally uncontroversial, implemented in https://github.com/matklad/once_cell/commit/084ffbdd5ee76a1fac1a78e6bdff0b23e18611a6 and relased as 1.0.6