flat assembler
Message board for the users of flat assembler.

Index > Linux > Circle gone wrong

Goto page Previous  1, 2, 3
Author
Thread Post new topic Reply to topic
Furs



Joined: 04 Mar 2016
Posts: 2493
Furs 01 Aug 2017, 19:02
Yes, globals are shared between threads (technically, you could even access the stack of the thread if you have its address, or anything else). That's one reason they are bad "mult-threading" practice, since they result in subtle bugs.

A way to use "globals" without putting them on the stack (local vars) is to have only one "local var" for each thread (or TLS, but that's more complicated) that is a pointer to all the "globals". So instead of keeping your vars as globals, keep them in a struct -- and pass the address of the struct to any function that needs the globals. Then each thread would have its own "globals". Of course you'll have to make a new struct for every thread, but that's the point of threads.

fork creates a new process so there's no sharing. It's easier in your case, but it has far more overhead.
Post 01 Aug 2017, 19:02
View user's profile Send private message Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall 02 Aug 2017, 14:59
keantoken wrote:
Are there any examples? I only found an assembly example using fork.


I'm using sys_clone to spawn CPU threads here: https://board.flatassembler.net/topic.php?t=13676
Post 02 Aug 2017, 14:59
View user's profile Send private message Visit poster's website Reply with quote
keantoken



Joined: 19 Mar 2008
Posts: 69
keantoken 02 Aug 2017, 17:09
Thanks, I always see your code and try to resist the urge to copy and paste large portions of it!
Post 02 Aug 2017, 17:09
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3

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