flat assembler
Message board for the users of flat assembler.

Index > Windows > Fasm 1.73 two threads write\read from value

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1815
Roman 22 Dec 2019, 06:16
I have two threads.

Thread1: mov [val1],10 ;this value dynamically changing

Thread2: mov eax,[val1]

My program crash. And i get error: Read\write

How fix this problem ?

I found this:
So, for reading I prefare to use CMPXCHG instruction with LOCK prefix, like:

LOCK CMPXCHG EAX, [J]
For writting:

MOV [J], EAX
SFENSE
Post 22 Dec 2019, 06:16
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1815
Roman 22 Dec 2019, 06:23
fasm 1.73 error cmpxchg rax, [val1]
Post 22 Dec 2019, 06:23
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1815
Roman 22 Dec 2019, 06:35
work fine

lock XCHG rax,[val1]
Post 22 Dec 2019, 06:35
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 22 Dec 2019, 06:38
If you have val1 aligned to a dword boundary then you can read and write the value from any thread without needing any locks. You will always get a fully written value, never any half written value.

If your program still crashes and val1 is aligned then I suspect your problem is with something else.
Post 22 Dec 2019, 06:38
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.