Sponsored Content
Top Forums Programming Multi thread data sharing problem in uclinux Post 302399305 by Loic Domaigne on Saturday 27th of February 2010 04:15:17 AM
Old 02-27-2010
Quote:
Originally Posted by Corona688
Try 'volatile int lock'. If you're going to modify a variable out from under something else in mysterious ways like threading or memory poking, you have to tell the compiler so. Otherwise it feels free to optimize it away on the assumption that it won't change until it changes it itself.

You should really be using mutexes, though.
Yes, you should use mutex. volatile alone (along with atomic operation) is not enough to guarantee correctness in multi-threaded program. The magic word here is: memory visibility. Interested readers might want to read: Mutex and Memory Visibility

Cheers,
Loïc.

---------- Post updated at 10:15 AM ---------- Previous update was at 10:07 AM ----------

Quote:
Originally Posted by mrhosseini
thanks,


yes, that was just an example that i used to test the threads behavior.

so the mutexes and any other data that i want to be shared must be defined as volatile, am i right?
No, absolutely not. As long as you use mutex correctly, there is no need to declare the variables (or the mutexes) volatile.

On a conforming POSIX platform, the compiler shall "know" how to deal with that kind of issue as long as you follow the memory visibility rules given in XBD 4.11 of IEEE Std 1003.1-2008.

Cheers,
Loïc.

This User Gave Thanks to Loic Domaigne For This Post:
 

8 More Discussions You Might Find Interesting

1. Programming

Multi threading using posix thread library

hi all, can anyone tell me some good site for the mutithreading tutorials, its application, and some code examples. -sushil (2 Replies)
Discussion started by: shushilmore
2 Replies

2. UNIX for Advanced & Expert Users

mmap vs shared memory - which is best for sharing data between applications?

Between mmap and shared memory which is the best method of sharing data between multiple applications, interms of speed? (2 Replies)
Discussion started by: nmds
2 Replies

3. Programming

forking. sharing global data in childs

hi, i want to write a code for forking 3 4 child. n wants that every child process one of the account from global account list. i wrote a program for that, but problem is every child is processing every account in list. what can me done to avoid it. attaching code with it #include <stdio.h>... (2 Replies)
Discussion started by: anup13
2 Replies

4. Solaris

Windows/Solaris data sharing

Hi all, I have a request from Developer team in my compagny, they would like to be able to share data between unix and windows world. 1. We would like to be able to see Unix data from Windows : ?Samba ? 2 We would like to be able to see windows data from Solaris (Mount point) : ?NFS server... (4 Replies)
Discussion started by: unclefab
4 Replies

5. Shell Programming and Scripting

data sharing between process

hi ! i want to make 2 c prog such tht if i give an input in 1st prog then i can use tht input in 2nd. so over all i want to do data sharing between process using files. plz give me suggestions how can i achieve this ? thanks ya! (2 Replies)
Discussion started by: Sgupta
2 Replies

6. Shell Programming and Scripting

Multi thread shell programming

I have a unix directory where a million of small text files getting accumulated every week. As of now there is a shell batch program in place which merges all the files in this directory into a single file and ftp to other system. Previously the volume of the files would be around 1 lakh... (2 Replies)
Discussion started by: vk39221
2 Replies

7. UNIX for Dummies Questions & Answers

Cross-compiling libiconv for uclinux

Hi everyone, I want to cross-compile libiconv for uclinux to create a static library. I use the following command : ./configure --enable-static --disable-shared --build=i686-pc-linux-gnu --host=nios2-unknown-linux-gnu --prefix=/home/captain/Programs/nios2-linux/uClinux-dist/staging/usr... (2 Replies)
Discussion started by: moganesh
2 Replies

8. Shell Programming and Scripting

Multi thread awk command for faster performance

Hi, I have a script below for extracting xml from a file. for i in *.txt do echo $i awk '/<.*/ , /.*<\/.*>/' "$i" | tr -d '\n' echo -ne '\n' done . I read about using multi threading to speed up the script. I do not know much about it but read it on this forum. Is it a... (21 Replies)
Discussion started by: chetan.c
21 Replies
SbStorage(3)							       Coin							      SbStorage(3)

NAME
SbStorage - The SbStorage class manages thread-local memory. This class manages thread-local memory. When different threads access the memory an SbStorage object manages, they will receive different memory blocks back. SYNOPSIS
#include <Inventor/threads/SbStorage.h> Public Member Functions SbStorage (unsigned int size) SbStorage (unsigned int size, cc_storage_f *constr, cc_storage_f *destr) ~SbStorage (void) void * get (void) void applyToAll (SbStorageApplyFunc *func, void *closure) Detailed Description The SbStorage class manages thread-local memory. This class manages thread-local memory. When different threads access the memory an SbStorage object manages, they will receive different memory blocks back. This provides a mechanism for sharing read/write static data. One important implementation detail: if the Coin library was explicitly configured to be built without multi-platform thread abstractions, or neither pthreads nor native Win32 thread functions are available, it will be assumed that the client code will all run in the same thread. This means that the same memory block will be returned for any request without considering the current thread id. Constructor &; Destructor Documentation SbStorage::SbStorage (unsigned intsize) [inline] Constructor. size specifies the number of bytes each thread should have in this thread-local memory management object. SbStorage::~SbStorage (void) [inline] The destructor. Member Function Documentation void * SbStorage::get (void) [inline] This method returns the calling thread's thread-local memory block. void SbStorage::applyToAll (SbStorageApplyFunc *func, void *closure) [inline] This method will call func for all thread local storage data. closure will be supplied as the second parameter to the callback. Author Generated automatically by Doxygen for Coin from the source code. Version 3.1.3 Wed May 23 2012 SbStorage(3)
All times are GMT -4. The time now is 01:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy