I try to set my process have negative nice value ex: -20 with syscall nice(int inc) or setpriority(int which, id_t who, int prio) I check with ps command, it hasn't work even syscall not return an error. Only positive value accepted. With negative value, nice value was set default 0.
Could you help me explain? Thanks
Related
Assume I made a function like below in swi-prolog.
function1(param) :- VALUE is 0, findValue(VALUE), write(VALUE).
However 0 is always printed out. findValue function is logically correct.'
Is it impossible to use calculated VALUE in function1?
Omit VALUE is 0.
By stating it, the function findValue will set the rest of the variables according to VALUE, because the claims you provide first are the axiom-level true ones, and the rest correspond to them.
For example, take
func(X):- X is 0.
If you query func(X). it will result in X=0 because it assumes you want to make an assignment.
However, if you query with a number like func(0). it will check if X==0 or not, resulting in a boolean answer.
In a CUDA C project, I have a pointer to float inside a structure called "p".
It is a pointer to device memory and it is called "p->deviceOutput". I am using CUDA-GDB to check the content of this pointer during execution: when I try to print it this is what happens:
(gdb) p *p->deviceOutput
$1 = 0
As you can see the printing returns something that looks like an int, definitely not a float.
I am really sure the pointer is a pointer to float so I am really confused by this behaviour.
Specifying the float format does not help:
(gdb) p/f *p->deviceOutput
$2 = 0
Actually I get the same behaviour using GDB as well.
I am working on Ubuntu 14.10 and my code was compiled with nvcc using -O0 and -g options.
Can anybody please explain what is going on and what should I do to inspect this memory location correctly? Thanks
gdb uses the g format specifier to printf (internally) when printing floating point values. Here's the interesting part of the description of g from the man page for printf:
Trailing zeros are removed from the fractional part of the result; a
decimal point appears only if it is followed by at least one digit.
So you're getting 0 because the floating point value is 0, and the g format specifier (used by gdb) prints an exact 0 without a decimal point, or any trailing 0's.
You can check that your variable is of type float using the ptype command, like this:
(gdb) ptype p->deviceOutput
I'm writing a program for my TI-nspire calculator in TI-BASIC, an optimised version of BASIC. From what I can tell, TI-BASIC is a compiled language. I have had more experience working with scripting languages, where you can define i as i+1, where the interpreter adds the previous value of i to 1 and makes that the new value of i. But since BASIC, from my understanding, is compiled, the calculator will set the value of i to the equation of i+1 and loop. Is there a way to set the value of i to the outcome instead of the equation?
You are wrong, it is perfectly fine to reference a variable in assigning a value to the same variable, it does not result in a loop. However, in TI-Basic you do not use the = operator to assign a value to a variable.
For z80 and 68k calculators use the →, character like this:
Local x
2→x
x+1→x
Return x
This returns 3. (Tested on a TI-89.)
On an TI-nspire use :=, like this:
Local x
x:=2
x:=x+1
Return x
This also returns 3.
Your understanding is wrong. Compilation does not change the semantics of an assignment. It is still an assignment.
And then, what number would the compiler use as the solution for i = i + 1?
As the title says I'm curious about the difference between "call-by-reference" and "call-by-value-return". I've read about it in some literature, and tried to find additional information on the internet, but I've only found comparison of "call-by-value" and "call-by-reference".
I do understand the difference at memory level, but not at the "conceptual" level, between the two.
The called subroutine will have it's own copy of the actual parameter value to work with, but will, when it ends executing, copy the new local value (bound to the formal parameter) back to the actual parameter of the caller.
When is call-by-value-return actually to prefer above "call-by-reference"? Any example scenario? All I can see is that it takes extra memory and execution time due to the copying of values in the memory-cells.
As a side question, is "call-by-value-return" implemented in 'modern' languages?
Call-by-value-return, from Wikipedia:
This variant has gained attention in multiprocessing contexts and Remote procedure call: if a parameter to a function call is a reference that might be accessible by another thread of execution, its contents may be copied to a new reference that is not; when the function call returns, the updated contents of this new reference are copied back to the original reference ("restored").
So, in more practical terms, it's entirely possible that a variable is in some undesired state in the middle of the execution of a function. With parallel processing this is a problem, since you can attempt to access the variable while it has this value. Copying it to a temporary value avoids this problem.
As an example:
policeCount = 0
everyTimeSomeoneApproachesOrLeaves()
calculatePoliceCount(policeCount)
calculatePoliceCount(count)
count = 0
for each police official
count++
goAboutMyDay()
if policeCount == 0
doSomethingIllegal()
else
doSomethingElse()
Assume everyTimeSomeoneApproachesOrLeaves and goAboutMyDay are executed in parallel.
So if you pass by reference, you could end up getting policeCount right after it was set to 0 in calculatePoliceCount, even if there are police officials around, then you'd end up doing something illegal and probably going to jail, or at least coughing up some money for a bribe. If you pass by value return, this won't happen.
Supported languages?
In my search, I found that Ada and Fortran support this. I don't know of others.
Suppose you have a call by reference function (in C++):
void foobar(int &x, int &y) {
while (y-->0) {
x++;
}
}
and you call it thusly:
int z = 5;
foobar(z, z);
It will never terminate, because x and y are the same reference, each time you decrement y, that is subsequently undone by the increment of x (since they are both really z under the hood).
By contrast using call-by-value-return (in rusty Fortran):
subroutine foobar(x,y):
integer, intent(inout) :: x,y
do while y > 0:
y = y - 1
x = x + 1
end do
end subroutine foobar
If you call this routine with the same variable:
integer, z = 5
call foobar(z,z)
it will still terminate, and at the end z will be changed have a value of either 10 or 0, depending on which result is applied first (I don't remember if a particular order is required and I can't find any quick answers to the question online).
Kindly go to the following link , the program in there can give u an practical idea regarding these two .
Difference between call-by-reference and call-by-value
how i can convert PWSTR variable to uppercase in vc++. I googled but didn't get the code sample.
EDITED
What i want to do with PWSTR variable is, a method's return type is PWSTR. I have to check whether the returned value is equal to string "Y". so whatever comes from return I am trying to UPPER its case then checking.
One more thing I want to know, how to use PWSTR var in if() condition checking.
thanks
There is _tcsupr_s and friends which should get you in the right direction.
EDIT:
Following on from your edit, you don't need to worry about converting to upper case for you to then do the comparison -- you can instead call the case insensitive string comparison function, _tcsicmp (or its friends if you're not compiling for Unicode) - there is example code if you follow the link, which also explains the importance of having set the correct locale to give the results you're expecting.
There you are - http://msdn.microsoft.com/en-us/library/sch3dy08%28v=VS.80%29.aspx