I'm currently reading a book which says a Mutex is only meant to be held for short periods of time -- and that a conditional variable should be used for extending locking (or even indefinitely).  My question is, why?  Obviously one wants to minimize the duration for which any lock is invoked, but why is a conditional variable preferred over a mutex?  After all, could one not create a conditional variable implementation using Mutexes?
217091
That "rule" makes sense to me.  You use a mutex when\nyou want access to a piece of shared data (ie. to update\na counter or insert something into a list).  Note that\nin many implementations, a mutex lock doesn't even\nnecessarily mean a trip through the scheduler (ie. short\nlocks can be done with a spinlock).\n\nGenerally speaking, you do *not* use a condition variable\nwhen you're just waiting for access to data.  Instead, you\nuse it when you're waiting for the data to reach some\ncondition state.  [In fact, the condition variable will\nbe used along with a mutex for access protection.]\n\nYou ask if you could create a condition variable with\nmutexes.  In a sense you could, but (1) it doesn't seem\nparticularly convenient (from the signalling perspective)\nand (2) you'd be inventing your own new design pattern\nthat some other engineer will have to figure out in order\nto support it.  Unless you have a good reason to do things\ndifferently, use the tools as others will expect [and\nhopefully they'll do the same for you :-) ]\n\nTo illustrate the idea of short and long waits, consider \nan example of how a condition variable might be used. \n\nLets say you have a consumer thread which doesn't want\nto begin processing objects in a queue until there are\nenough to meet some threshhold.  Other threads might\nacquire and release the associated data access mutex\nmany times to add elements, but only when they've\nhit the threshhold will one of them explicitly signal\nthe consumer thread to check the condition and begin work.\nIn this situation, the mutex is used for short term\naccesses, but a condition variable is used for a \nlonger-term wait (until the condition is satisfied).
122145
You say don't use any operators, but that pretty much makes almost every program impossible.  I assume that you don't care about some of the "other" operators that include the stream insertion operators for inputting and outputting results, the function call operator, and the member operator, at the very least.  List of operators:\nhttp://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B\n\nIf you only want to restrict the use of +/-, here's someone that wrote an adder that sort of simulates how it's done in hardware, but he uses lots of bitshift and bitwise operators:\nhttp://www.devmaster.net/forums/showthread.php?t=1727\n\nHere's my little solution, which doesn't even utilize assignment or comparison operators, though it isn't very useful for adding large numbers since it allocates memory then just looks at how much is allocated.\n\n\n#include <iostream>\n#include <string>\nusing namespace std;\n\nint main(void)\n{\n   int a, b;\n   string sum;\n\n   cin >> a >> b;\n   sum.resize(a, 'z');\n   sum.append(b, 'z');\n   cout << sum.size() << endl;\n   return 0;\n}\n// it wouldn't let me indent when I pasted...
619520
"if all inputs are low then the output is low" is true for AND, OR, and XOR.\n\n"if all inputs are low then the output is high" is true for NAND, NOR, and XNOR.\n\nBy referring to the "remaining 6 LOGIC GATES", you must be including NOT. It allows only one input, but one could still say that "if all inputs are low then the output is high".
652946
Memory Handling.\nWhatever memory space you occupy by instantiating the objects should be released after your use.\nType Casting should also be taken care.
88273
<?= is used as a shortcut to echo or print a variable.\n\n<?=$variable_name;?>\n\nis the same as:\n\n<?print $variable_name;?>
249945
First: Pay attention in class, this is stuff they teach in 7th grade. \n\nSecond: the answer is likely A because that's what the experimenter is 'controlling' but it's a very poorly worded question. The common verbage used is 'dependant' or 'independant' variables. \n\nI'm assuming that your teacher is either ignorant or very mean. Either way, my condolences.
154506
I'm afraid I haven't used the pthread library you're using, so I can;t be sure of this, but in other thred libraries I've used, not only do you have to create a thread you actually have to explicitly Start it as well, are you sure you're not missing a call to some function that would actually start the thread running?
306725
protected void BuildThread() \n{ \n  string s ; \n  s = "This is output from another thread"; \n  Console.WriteLine(s); \n}\n\nthread = new Thread(new \nThreadStart(BuildThread)); \nthread.Start();\n\nYou can kill a thread:\nif ( thread.IsAlive ) \n{ \n     thread.Abort(); \n}\n\nor you can suspend it:\nif (thread.ThreadState = ThreadState.Running) \n{ \n     thread.Suspend(); \n}\n\nWhat is your need for a thread?
411228
all types in java are signed.  that's how it was designed.  i have found it to be a problem only very rarely.
13250
Elflemming is correct.\nWhen you run the class state it is loaded in JVM. Then when you use Example class it is then loaded on JVM. Keep in mind, no instance is created, only class is loaded.\nWhenever you use a class for first time JVM loads it . When loading class it initializes all static variable and executes static initializer.( If exists.)\nSo no instance of exaple class will be created.
56355
you havn't closed "void determinecost (...)" function with curly braces " } "\n\nin c++, you have to close any block of code with } that has been opened with {
500129
there is no "code" for it. The compiler evaluates it at the compile time, and replaces with the actual number.\nThere is no way to write a function that would did that at run time, because at run time, there is not type information available - only addresses of variables not their sizes
500220
A partial answer.\nThe case of W_Y(t) is easy: this is the sum of Y(t) variables that are exponentially distributed and independent of Y. So the sum's expectation is the exponential expectation (1/c) times the expectation of Y(t), which is ct (Y(t) has the Poisson distr with para ct). So\n\nE(W_Y(t)) = (1/c)ct = t.\n\nThat is, the average wait in the process X until its number of events is equal to the number of events in Y at time t is the average inter-event time (1/c) times the number of events in Y at time t (which is ct), and this is simply t.\n\nThe case of W_X(t) is not so easy because the variables and their number in the sum are no longer independent.\nEW_X(t) equals the sum over n of the probability that that X(t)=n (which is exp(-ct)(ct)^n/n!, the Poisson probability) times the expectation of W_n conditional on W_n being less than t and W_n+1 being greater than t (this is a way of saying that X(t)=n). So EW_X(t) is certainly less than t. Also, W_n has the gamma distribution, and in principle the conditional expectation could be calculated from that.
580423
When variables are passed to a procedure or function they can be IN, OUT or INOUT.  An IN variable is passed into the procedure or function and is used, but can not be changed.  An OUT variable is passed to the procedure but it can be changed and left in the changed state when the procedure ends. \n\nAn INOUT variable is passed to a procedure or function, and it can be used by the block, changed by the block, and left in a “changed” state when the block ends.  A function can only be passed an IN variable and must return a variable.  If this is confusing, don’t worry.  When we get to name blocks and provide some examples it will be much cleare
365900
2points answer.\n\nTry again.  Your question is unreadable.\n\nDon't use x as both a variable and an operator.  On that first one, which side of the multiplication is the variable x on?\n\nI don't understand what the third one is trying to say at all.\n\nUse * for multiplication, use / for division.\n\nAnd most importantly, what answer do you want from this?  You aren't showing any equalities or inequalities.  The second one shows five variables, so there aren't enough expressions to solve them anyway.
18562
D. If a variable some times equal to its both of the bounds, it will be mentioned or written as [a,b] generally called as values between a and b inclusive of a and b both, as per the case mentioned here, the variable can take any value between a and b inclusive of a, so a<= variable < b written as [a,b[
495815
Try this:\n\nvoid addIt(int* begin, int* end, int x)\n{\nint* p;\nfor (p=begin; p!=end; ++p) {\n*p = *p + x;\n}