The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Threads and Threads Count ? varungupta UNIX for Advanced & Expert Users 2 03-21-2008 06:23 PM
how to read POSIX? robin.zhu UNIX for Dummies Questions & Answers 3 07-15-2006 07:07 AM
what can I get the posix standard? crashsky UNIX for Advanced & Expert Users 2 02-11-2004 10:30 PM
Unix(posix) Haris Astreos High Level Programming 1 11-10-2002 07:45 AM
ANSI C vs POSIX bb00y High Level Programming 2 11-05-2002 06:20 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 12-15-2006
!_30's Avatar
Registered User
 

Join Date: Sep 2006
Location: Romania , Ploiesti
Posts: 37
POSIX threads

Hello !

Let's supose I have a main function in C , and two POSIX threads. I give you an example down :

Code:
int main() {
int something;
char else[];
void *FirstThread();
void *SecondThread();
 ..
<start those two pthreads ..>
return 0;}
void *FirstThread() { ... }
void *SecondThread() { ... }
First and Second thread will use something and else , int and char . Do thow two pthreads share the same space of memory ? I mean , First thread will modify the same something ( place of memory ) like Second Thread ?
Reply With Quote
Forum Sponsor
  #2  
Old 12-15-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,274
Are you asking if you create two threads, can they modify the same memory?
Yes.
You prevent that by:
1. keeping almost all the variables they change declared local to the function. That way they cannot hurt anybody else's data.
2. For shared data, set up a mutex, so that only one function is able to change shared data at one time.

In your case, if you pass a reference to int and char to both functions, then you have a problem.
Reply With Quote
  #3  
Old 12-15-2006
!_30's Avatar
Registered User
 

Join Date: Sep 2006
Location: Romania , Ploiesti
Posts: 37
Oh yes , I figure it out.

Thanks again !
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0