<div>Hi:</div><div>In our frontend we are attempting to build a lock mechanism without using system apis like pthreads and whatnot for internal reasons.</div><div>In order to achieve this we are now creating a int32 type GV, and then use atomic load/store and comparisons. The generated IR looks like the following:</div><div><br></div><div>```</div><div>@Flag = private global i32 0, align 4</div><div>%0 = load atomic i32, i32* @Flag acquire, align 4</div><div>%1 = icmp eq i32 %0, 1</div><div>.......</div><div>store atomic i32 1, i32* @Flag release, align 4</div><div>```</div><div><br></div><div>However when inspecting the generated assembly on x86-64, the following assembly was generated:</div><div>```</div><div><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;">mov        qword [rbp+var_50], rcx</p><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;">mov        qword [rbp+var_48], rdx</p><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;">mov        rbx, rsi</p><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;">mov        r15, rdi</p><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;">mov        eax, dword [l_Flag]                ; l_Flag</p><p style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;">cmp        eax, 0x1</p></div><div>```</div><div><br></div><div>Which to my best knowledge is not atomic. </div><div>I'd like to know how do I fix my frontend to make sure the locking mechanism works</div><div><br></div><div><br></div><div>Zhang</div><div><br></div><div><includetail><!--<![endif]--></includetail></div>