pthread_cond_timedwait returns error 454 (freebsd) - pthreads

I can't find any info about this error on google, so I'm posting here to see if anyone knows.
Basically, my code has a snippet that looks something like this:
int rc = pthread_cond_timedwait(&cond, &mutex, &ts);
if ( (0 != rc) && (ETIMEDOUT != rc)) {
assert(false); // This should not happen.
}
Occasionally, my program will crash and the corefile will show that rc = 454.
454 does not map to any of the error codes in errno.h. In addition, looking at the list of possible return values that can be given by pthread_cond_timedwait(), none of them resemble 454.
I've looked into the parameters passed in, but I don't really know how to interpret them or where I would be able to learn how.
(gdb) p *mutex
$20 = {m_lock = {m_owner = 100179, m_flags = 0, m_ceilings = {0, 0}, m_spare = {0, 0, 0, 0}}, m_type = PTHREAD_MUTEX_ERRORCHECK, m_owner = 0x80a004c00, m_count = 0, m_refcount = 0, m_spinloops = 0, m_yieldloops = 0, m_qe = {tqe_next = 0x0, tqe_prev = 0x80a004f10}}
(gdb) p *cond
$21 = {c_lock = {m_owner = 0, m_flags = 0, m_ceilings = {0, 0}, m_spare = {0, 0, 0, 0}}, c_kerncv = {c_has_waiters = 1, c_flags = 0, c_spare = {0, 0}}, c_pshared = 0, c_clockid = 0}
(gdb) p ts
$22 = {tv_sec = 1400543215, tv_nsec = 0}
The internals of "cond" look suspicious to me but, as I mentioned, I have no way to be sure.

Since it's FreeBSD, we can look at the source to see where you're getting the mysterious 454 return from. Using the source archives at fxr.watson.org, I searched for the symbol pthread_cond_timedwait and the only credible references are in the GLIBC27 code, so we'll look there.
In source file pthread_cond_timewait.c, we see the function __pthread_cond_timedwait. There are three returns; the first is EINVAL, the second is the return from __pthread_mutex_unlock_usercnt and the third is the return from __pthread_mutex_cond_lock. Now that I've given you the tools to find the answer, you can go chase down the rest of the answer yourself. The 454 must have come from one of the unlock or lock call.
The versioned_symbol macro at the bottom of the source file is what makes the local __pthread_cond_timedwait call the global pthread_cond_timedwait function.

Related

z3 Solver and solve give different results

I have been experimenting with z3 (version '4.8.7' obtained through pip3) and found this (apparent) discrepancy.
t, s0, s, u, a, v = Reals('t s0 s u a v')
equations = [v == u + a*t, s == s0 + u*t + a*t**2/2,
v**2 - u**2 == 2*a*s]
problem = [t == 10, s0 == 0, u == 0, a == 9.81]
solve(equations+problem)
This gives the correct output for s:
[a = 981/100, u = 0, s0 = 0, t = 10, s = 981/2, v = 981/10]
But when I use the Solver, the result is different:
solver = Solver()
solver.check(equations+problem)
solver.model()
This gives a wrong output for s, though it gets v right.
[t = 10, u = 0, s0 = 0, s = 0, a = 981/100, v = 981/10]
s should be (1/2) * (981/100) * 100 which is the result in solve.
Am I missing something obvious in z3's Solver or is this a bug? Thank you.
The issue here is that the argument to solver.check are extra assumptions the solver can make as it solves the constraints, not the actual constraints to check. See the documentation here: https://z3prover.github.io/api/html/z3py_8py_source.html#l06628
The correct call would be:
solver = Solver()
solver.add(equations+problem)
print solver.check()
print solver.model()
that is, you add the constraints, and then call check with no arguments. This would match what solve does. The argument to check are used if you want to check validity under some extra assumptions only.

Resultant weight vector has same values in SAS/IML

I'm trying to create a binary perceptron classifier using SAS to develop my skills with SAS. The data has been cleaned and split into training and test sets. Due to my inexperience, I expanded the label vector into a table of seven identical columns to correspond to the seven weights to make the calculations more straightforward, at least, given my limited experience this seemed to be a usable method. Anyway, I run the following:
PROC IML;
W = {0, 0, 0, 0, 0, 0, 0};
USE Work.X_train;
XVarNames = {"Pclass" "Sex" "Age" "FamSize" "EmbC" "EmbQ" "EmbS"};
READ ALL VAR XVarNames INTO X_trn;
USE Work.y_train;
YVarNames = {"S1" "S2" "S3" "S4" "S5" "S6" "S7"};
READ ALL VAR YVarNames INTO y_trn;
DO i = 1 to 668;
IF W`*X_trn[i] > 0 THEN Z = {1, 1, 1, 1, 1, 1, 1};
ELSE Z = {0, 0, 0, 0, 0, 0, 0};
W = W+(y_trn[i]`-Z)#X_trn[i]`;
END;
PRINT W;
RUN;
and the result is a column vector with seven entries each having value -2.373. The particular value isn't important, but clearly, a weight vector that is comprised of identical values is not useful. The question then is, what error in the code am I making that is producing this result?
My intuition is that something with how I am trying to call each row of observations for X_trn and y_trn into the equation is resulting in this error. Otherwise, it might be due to the matrix arithmetic in the W = line, but the orientation of all of the vectors seems to be appropriate.

How to iterate from last index to first in table

bestSword = {
{name = 'www' , lvl = 35, atk = 38, npcPrice = 15000 , buyPrice = 0},
{name = 'bbb' , lvl = 40, atk = 40, npcPrice = 20000 , buyPrice = 0},
{name = 'eee' , lvl = 50, atk = 42, npcPrice = 25000 , buyPrice = 0},
{name = 'sss' , lvl = 55, atk = 43, npcPrice = 30000 , buyPrice = 0},
{name = 'aaa' , lvl = 60, atk = 44, npcPrice = 30000 , buyPrice = 0},
{name = 'qwe' , lvl = 70, atk = 46, npcPrice = 35000 , buyPrice = 0},
{name = 'asd' , lvl = 82, atk = 48, npcPrice = 60000 , buyPrice = 0}
}
I have this table, how can I iterate from last index to first? It should break depends from lvl. I just want to show this table from the best weapon. For example if Player have level 53, then I want to show only weapons for his lvl or lower. I need to show that from the best one (at top) its why I want to iterate from the last index. Could someone help?
EDIT:
Thanks for help. There is still a problem that I need this changed table later. It shows all fine but I need to buy all litems from this (changed) list later. So I must replace in some way this 2 tables. Is there any easy way to do that? I tried to remove elements from this table but it still not works.
Or its possible to make some map in Lua? It must be dynamic sized so i cant use table i guess. Something with key - value
A numeric for loop, counting down, is the best option:
local t = {2,4,6,8}
for i = #t, 1, -1 do
print(t[i])
end
Assuming that the table is not necessarily sorted into level order (unlike the example), we need to do two things:
Find which swords are in the level range
Sort them into descending order
Now the first one in the temporary table is the "best" sword.
Like this:
bestSword = {
{name = 'www' , lvl = 35, atk = 38, npcPrice = 15000 , buyPrice = 0},
{name = 'bbb' , lvl = 40, atk = 40, npcPrice = 20000 , buyPrice = 0},
{name = 'eee' , lvl = 50, atk = 42, npcPrice = 25000 , buyPrice = 0},
{name = 'sss' , lvl = 55, atk = 43, npcPrice = 30000 , buyPrice = 0},
{name = 'aaa' , lvl = 60, atk = 44, npcPrice = 30000 , buyPrice = 0},
{name = 'qwe' , lvl = 70, atk = 46, npcPrice = 35000 , buyPrice = 0},
{name = 'asd' , lvl = 82, atk = 48, npcPrice = 60000 , buyPrice = 0}
}
myLevel = 53 -- wanted level
-- temporary table
possible = { }
-- extract ones which are in range
for k, v in ipairs (bestSword) do
if v.lvl <= myLevel then
table.insert (possible, v)
end -- if
end -- for
if #possible == 0 then
print "No matching swords"
else
table.sort (possible, function (a, b) return a.atk > b.atk end )
bestSword = possible [1]
print ("Best sword is", bestSword.name, "lvl =", bestSword.lvl,
"atk = ", bestSword.atk)
end -- if
Or its possible to make some map in Lua? It must be dynamic sized so i cant use table i guess. Something with key - value
Tables in Lua are maps. Every table has key/value pairs. The one you are using there are simply numerically-keyed tables.
All tables are dynamically sized.

How to increment a variable in a table and access it?

I have a table defined like:
local counter = {
deleted = 0,
moved = 0,
sumOfFileSize = 0,
}
I have tried the following to increment or get the values, but it doesn't work:
increment: counter.deleted = counter.deleted + 1
get: counter.deleted
How can I successfully modify or read these values?
if youre using in some functions you need to declare whitout local, and meaby you can declare it in the top of the file with
counter={deleted = 0,
moved = 0,
sumOfFileSize = 0}
for access in all the functions you want.
The problem is from another place because i try this in console and here its the result, so the problem isnt lua
counter = {
deleted = 0,
moved = 0,
sumOfFileSize = 0,
}
print(counter)
table: 0x7fb1e2e005d0
counter.deleted = counter.deleted + 1
print(counter.deleted)
1
counter.deleted = counter.deleted + 1
print(counter.deleted)
2
counter.deleted = counter.deleted + 1
print(counter.deleted)
3

Unclassifiable Statement at (1), Fortran90 error

I keep getting this error when I try to compile. I am not quite sure what the issue is. I am not the best at coding, and thus, debugging is not my strong suit. Any ideas whats causing the error?
PROGRAM Atmospheric_Reflection
IMPLICIT NONE
REAL*8:: Wavelength = 0.200D-6, WaveNumber = 0.0, pi = 3.14159265, Length(1:71) = 0, Number(1:71) = 0, IndexOfRe(1:71) = 0
INTEGER:: i = 0
!Calculate the wave number for wavelengths varying from 0.2 micrometers to 1.6 micrometers in increments of 0.02 micrometers
i = 1
DO WHILE (Wavelength <= 1.600D-6)
WaveNumber = 1/Wavelength
Length(i) = Wavelength
Number(i) = WaveNumber
IndexOfRe(i) = 1 + (((5791817.0/(238.0185 - WaveNumber**2))+(167909.0/(57.362-WaveNumber**2))))D-8
Wavelength = Wavelength + 0.02D-6
i = i+1
END DO
END PROGRAM
Possibly the D-8 at the end of this line
IndexOfRe(i) = 1 + (((5791817.0/(238.0185 - WaveNumber**2))+(167909.0/(57.362-WaveNumber**2))))D-8

Resources