LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-03-2004, 11:58 AM   #1
cardias
LQ Newbie
 
Registered: Aug 2004
Posts: 5

Rep: Reputation: 0
pthreads: mutex initializer


Hi there!

i'm using the pthreads (posix threads) but i have a doubt germane to mutex declaration.
when i initialize a mutex (as below), i want to lock/unlock any of the 4 variables: G_a, G_b, G_c or G_d. if i use the code below, i'm not sure if "my_mutex" can be used to lock/unlock the 4 variables or only the first one (G_a). i would like to avoid creating a mutex for every single variable.

pthread_mutex_t my_mutex = PTHREAD_MUTEX_INITIALIZER;
struct data G_a;
struct data G_b;
int G_c;
int long G_d;

i haven't found anything about it. i would appreciate any suggestions.

thanks,
cardias.
 
Old 09-03-2004, 12:53 PM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
as long as all of the code that tries to access one of those variables first locks the mutex, you won't have a problem.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Named mutex in Linux tbruer1138 Programming 6 05-17-2016 09:25 AM
difference mutex vs. semaphore? Thinking Programming 1 11-16-2005 05:26 AM
timeout for a mutex lock dmail Programming 6 10-24-2005 07:22 AM
Apt-get and mutex error? Bez625 Linux - Newbie 1 09-28-2005 02:42 PM
pthread mutex issue gauge73 Programming 6 04-20-2004 05:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration