Synchronization Variable Storage


 
Thread Tools Search this Thread
Top Forums Programming Synchronization Variable Storage
# 1  
Old 11-08-2011
Synchronization Variable Storage

We know that all the threads in process share the process address space.
We have various synchronization mechanisms like semaphore, mutex, spinlock, critical sections etc . used for thread syncronization.
I want to know in which part of the process address space are these synchronization variables stored?
How one thread gets access to the syncronization variable declared in another thread? Pls correct me if this question is improper.
# 2  
Old 11-08-2011
If you make them local variables, they're in stack space. If you make them global variables, they're in global variable space. If you allocate them with malloc, they're in heap space. They don't need to be stored anywhere in particular.

All threads in the same process have access to the process' entire memory space. As such, there is no more access to "get", they already have access to everything. The problem is how to access things safely, avoiding race conditions and cache effects. That's what mutexes and other IPC are for.

As for transferring variables from thread to thread, you could pass in pointers to both threads, transfer through a global data structure, communicate by pipes or sockets, or many other means.

Last edited by Corona688; 11-08-2011 at 10:35 AM..
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 11-09-2011
They are just variables (ofcourse the pthread lib treat them specially) so where ever you declare/define them there they’d appear; the only thing is their scope and visibility to pthreads that should guide you the location to declare them.

Like to add a quick-tip:
You can look at the process (having pid = x) memory area at /proc/<pid>/maps
Code:
cat /proc/x/maps

Gives you all *.so and other memory area of the process (in terms of memory ranges).

If you have to see the location of a perticular variable; just print it's address from your program and while the process is running, look at the location (find the range slab) where the address is falling. That is the location of your variable in the program. This is true for any address your program uses.

Thanks.
This User Gave Thanks to Praveen_218 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable storage using awk

Hi, there is a file which contains some values in column format. I want to store those values in a variable.but when i am using awk it is storing all the values at a time. x=`awk '{print $1}' test2.txt` echo $x ab cd mn jk yt but i want the values to be stored one by one in that variable.... (3 Replies)
Discussion started by: arijitsaha
3 Replies

2. Programming

Variable storage locations ...

I've got the following two queries: 1) What's the difference in performance if a variable storage is at bss and not at the data section (apart from the initialization to zero in case of data section variables --like static variables). In general, why a developer need to bother about the... (1 Reply)
Discussion started by: Praveen_218
1 Replies

3. Programming

static variable storage

Hi, Where are the static variables actually stored in memory. Is it in .bss? In that case how is its storage different from global variables? From the ELF data is it possible to see the storage of different variables used in the program? eg: static int temp1; int gtemp1; main() {... (1 Reply)
Discussion started by: naan
1 Replies
Login or Register to Ask a Question