# Advice on using unsafe\_wrap to view integers as atomic integers

**URL:** <https://discourse.julialang.org/t/advice-on-using-unsafe-wrap-to-view-integers-as-atomic-integers/67918>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 9, 2021, 8:35am UTC](https://discourse.julialang.org/t/advice-on-using-unsafe-wrap-to-view-integers-as-atomic-integers/67918 "2021-09-09T08:35:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [September 9, 2021, 8:48am UTC](https://discourse.julialang.org/t/advice-on-using-unsafe-wrap-to-view-integers-as-atomic-integers/67918/2 "2021-09-09T08:48:00Z")

</div>

If you want to manipulate integers in an array atomically, see [https://github.com/tkf/TSXPlayground.jl/blob/master/src/UnsafeAtomics.jl](https://github.com/tkf/TSXPlayground.jl/blob/master/src/UnsafeAtomics.jl) and its usage. Not sure how much of this is “legal” though.

`unsafe_wrap(Vector{Atomic{Int32}}, pointer(::Vector{Int32}), _)` doesn’t work because it means interpreting two consecutive `Int32`s as a pointer to the memory location of the mutable struct `Atomic{Int32}` (assuming 64 bit machine).

---

_[View the full topic](https://discourse.julialang.org/t/advice-on-using-unsafe-wrap-to-view-integers-as-atomic-integers/67918)._
