The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 09:23 PM
how to read POSIX? robin.zhu UNIX for Dummies Questions & Answers 3 07-15-2006 10:07 AM
what can I get the posix standard? crashsky UNIX for Advanced & Expert Users 2 02-12-2004 01:30 AM
Unix(posix) Haris Astreos High Level Programming 1 11-10-2002 10:45 AM
ANSI C vs POSIX bb00y High Level Programming 2 11-05-2002 09:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-15-2006
!_30's Avatar
!_30 !_30 is offline
Registered User
  
 

Join Date: Sep 2006
Location: Romania
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 ?
  #2 (permalink)  
Old 12-15-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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.
  #3 (permalink)  
Old 12-15-2006
!_30's Avatar
!_30 !_30 is offline
Registered User
  
 

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

Thanks again !
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0