I am trying the understand the conditional variable concept.
I went through the following site: https://computing.llnl.gov/tutorials...itionVariables
I understand that condition variables allow threads to synchronize based upon the VALUE of data.
When the data acheives a particular value then it signals the condition variable.
But in such cases when we monitor a particular value of a variable then why there is a need for condition variable here?
Why cannot we use another mutex when the variable acheives the needed value?
Example shown in the above site:
This simple example code demonstrates the use of several Pthread condition variable routines. The main routine creates three threads. Two of the threads perform work and update a "count" variable. The third thread waits until the count variable reaches a specified value.
For instance in the example shown in the above site why cannot we use an another mutex to monitor variable "count" value?
This new mutex will be locked by the inc_count() and unlocked when variable "count" becomes to desired value.
The watch_count() thread will wait for the availibility of the mutex.
The second mutex will act as a signalling mutex to be used instead of condition variable.
I hope I am able to clearly explain the doubt.
Last edited by rupeshkp728; 11-11-2011 at 07:36 AM..
Reason: code
I do not understand your confusion very well. Here is a stab at an answer that may help.
pthread_cond_t variables MUST BE USED with separate mutexes. Mutexes do not take on values like 42. Think of cond_t variables as special add-on features for mutexes that take on a value.
See this page, scroll down to condition variables.
I do not see the condition variable is holding any value.
The condition variable is manually signalled when a variable reaches a certain value.
So here why cannot we have signal using an another mutex instead of condition variable.
The other thread will be waiting for this second mutex to be released.
Is my doubt clearly explained now?
Below are three variables, which I want to pass into variable RESULT1
username1=userid
poihostname1=dellsys.com
port1=8080
How can I pass these variables into below code...
RESULT1=$((ssh -n username1@poihostname1 time /usr/sfw/bin/wget --user=sam --password=123 -O /dev/null -q... (4 Replies)
Sometimes it is handy to protect long scripts in C++.
The following syntax works fine for simple commands:
#define SHELLSCRIPT1 "\
#/bin/bash \n\
echo \"hello\" \n\
"
int main ()
{
cout <<system(SHELLSCRIPT1);
return 0;
}
Unfortunately for there are problems for:
1d arrays:... (10 Replies)
Hi All,
i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way??
#!/bin/ksh
##script is sample.ksh
age=$1
gender=$2
class=$3
.
.
.... (3 Replies)
HI
My doubt may be basic one but I need to get it clarified..
When i use "if" condition that checks for many AND, OR logical conditions
like
if ]; then
return 0
fi
Even the if condition fails it returns as zero.. Any clue..
But if i add else condition like
if ]; ... (2 Replies)
hi,
I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command
Here are my simple script
After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Executed the following if conditions .. and got different results .
only (( )) gave correct o/p with all scenarios .
Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition.
And why each condition gave different result.
1.... (2 Replies)
Hi,
I am reading through the pthreads tutorial and had a question on the example they have given for condition variables. Here is the code snippet:
This is what the thread waiting on the condition variables doing:
pthread_mutex_lock(&count_mutex);
while (count<COUNT_LIMIT) { <---... (10 Replies)
I am trying to understand the exact difference between condition variables and mutexes in thread synchronization ?. I know mutex will control the thread access to shared data and condition variables will be useful for waiting for certain event or condition to occur . But I couldn't understand
why... (2 Replies)
Hello everybody,
I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)