From: "J.A. Magallon" <jamagallon@able.es>
To: "Robert M. Hyatt" <hyatt@cis.uab.edu>
Cc: Lista Linux-SMP <linux-smp@vger.kernel.org>
Subject: Re: per-thread global variables
Date: Sat, 13 Jul 2002 02:12:34 +0200 [thread overview]
Message-ID: <20020713001234.GA1675@werewolf.able.es> (raw)
In-Reply-To: <Pine.LNX.4.33.0207121415220.15713-100000@crafty>; from hyatt@cis.uab.edu on Fri, Jul 12, 2002 at 21:17:01 +0200
On 2002.07.12 Robert M. Hyatt wrote:
>
>
>I do this in Crafty. The approach I chose is to create a structure
>for each thread (I also use clone() since the glibc guys broke
>pthreads a while back) and then let each thread set its pointer to
>its own private structure (really shared, but since only one thread
>has a pointer to each structure, it is like a private but global
>group of variables).
>
>Doing it like this will guarantee it will work with any compiler,
>which might be a plus...
>
I think something is very dark for me...The hard way in pseudo-C
short id[PID_MAX];
#define setself(k) do { tid[getpid()]=k; } while(0)
#define self() (id[getpid()])
// master
setself(-1);
// slaves
for (i in 0..nslaves-1)
clone(f(),CLONE_VM,i);
f(void *arg)
{
setself((int)arg);
print(self());
}
But how about the 32K*2 array ??? (hash table, ordered vector and binary
search...)
Quoting your answer:
>pthreads a while back) and then let each thread set its pointer to
^^^
>its own private structure (really shared, but since only one thread
How do you define 'its' pointer ? That is like if I just defined
short id;
and tried to set 'its id' for each thread ?
Whichever method you use, at the end you always need one, the last, the
unique variable (one int, a pointer to a data area), declared as a global
variable in C that you need to be distinct for each thread. The only
thing (in my short undestanding) that can distinguish a thread from one
other is _pid_. Of course, I don't want to mess passing an info struct
to all functions in my code.
On IRIX, you have a
// Fixed address space always private for each process/thread
#define PRDA ((struct prda *)0x00200000L)
struct prda* thrprda;
int* self;
f(int k)
{
thrprda = (struct prda*)PRDA; // The magic global pointer
// different for each thread
self = &(thrprda->user_area);
*self = k;
}
If Linux supported this it will make many many things simpler.
A fixed zone of virtual address space that is never shared.
Or perhaps... Could I do in Linux:
#define PRDA ((void*)0x00200000L) // Or get any free address space
int* self = PRDA; // will be shared over clone(), so we fix it before
for (i in 0..nslaves-1)
clone(f(),CLONE_VM,i);
f(void *arg)
{
// Get a chunk, mapped on a fixed address, and do not propagate the
// map to parent or siblings
mmap(self,1024,PROT_??,MAP_ANONYMOUS|MAP_FIXED|MAP_PRIVATE,0,0);
*self = (int)arg;
}
??
TIA
--
J.A. Magallon \ Software is like sex: It's better when it's free
mailto:jamagallon@able.es \ -- Linus Torvalds, FSF T-shirt
Linux werewolf 2.4.19-rc1-jam3, Mandrake Linux 8.3 (Cooker) for i586
gcc (GCC) 3.1.1 (Mandrake Linux 8.3 3.1.1-0.7mdk)
next prev parent reply other threads:[~2002-07-13 0:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-12 16:15 per-thread global variables J.A. Magallon
2002-07-12 16:43 ` Alan Cox
2002-07-12 16:34 ` J.A. Magallon
2002-07-12 17:41 ` Alan Cox
2002-07-12 19:17 ` Robert M. Hyatt
2002-07-13 0:12 ` J.A. Magallon [this message]
2002-07-13 1:50 ` Alan Cox
2002-07-13 1:11 ` J.A. Magallon
2002-07-13 2:05 ` J.A. Magallon
2002-07-13 3:20 ` Robert M. Hyatt
2002-07-13 9:43 ` J.A. Magallon
2002-07-13 14:07 ` Robert M. Hyatt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020713001234.GA1675@werewolf.able.es \
--to=jamagallon@able.es \
--cc=hyatt@cis.uab.edu \
--cc=linux-smp@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.