flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Linux > Circle gone wrong

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



Joined: 04 Mar 2016
Posts: 567
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: 152
Location: Poland

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

_________________
https://github.com/michal-z
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
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.