1. Task ids weird behavior
- Posted by AndySerpa Jan 11, 2010
- 970 views
Statements like:
if task_self() = 2 then .. end if
never evaluate as true. It is acting as if the task id returned from task_self is a float that isn't quite equal to the integer value.
However,
if floor(task_self()) = 2 then .. end if
works (it is is true).
And it also seems to work if you aren't using actual numbers in the comparison, but a variable instead. BUT not if it is declared as an integer.
integer x x = 2 if task_self() = x then .. end if
doesn't work.
But if x is declared as an atom, object, or a sequence (and you use x[something] in the if statement), then it does work.
This behavior seems restricted to if statements. If I make an expression outside an if statement like
y = (x = 2)
then y will evaluate correctly (to 0 or 1).
In short, task_ids ( at least the ones returned from task_self() ) in if statements aren't being treated as integers and can't even be compared to integers unless you convert to an integer with something like floor().
What's up with that?
(This seems to hold for both Eu v3 & v4)
2. Re: Task ids weird behavior
- Posted by jimcbrown (admin) Jan 12, 2010
- 965 views
Statements like:
if task_self() = 2 then .. end if
never evaluate as true. It is acting as if the task id returned from task_self is a float that isn't quite equal to the integer value.
In short, task_ids ( at least the ones returned from task_self() ) in if statements aren't being treated as integers and can't even be compared to integers unless you convert to an integer with something like floor().
What's up with that?
(This seems to hold for both Eu v3 & v4)
This behavior appears to be by design. The tid is set specifically as a double internally, not an int. I am not aware of the specific reasons for this design, but its not a bug or a mistake or an accident.
This behavior seems restricted to if statements.
I have no idea why that's the case. Maybe that is a bug.
3. Re: Task ids weird behavior
- Posted by AndySerpa Jan 12, 2010
- 983 views
Well, if you can't rely on a simple comparison to work as it usually does it can certainly create bugs in your programs. Seems like there is a type conversion missing somewhere.
I've also been having a problem recently with tasking where if I force a crash for debugging purposes (like with ? 1/0) just after a task_yield() statement, it will throw a machine-level error instead of a proper crash with .err files written with full debugging info. I can't as yet reproduce this behavior in a simple example, but it has happened quite a bit in programs that have complex task-switching.
4. Re: Task ids weird behavior
- Posted by mattlewis (admin) Jan 16, 2010
- 914 views
Statements like:
if task_self() = 2 then .. end if
never evaluate as true. It is acting as if the task id returned from task_self is a float that isn't quite equal to the integer value.
It's a bug in emit.e. When the TASK_SELF op is emitted, the resulting temp is incorrectly identified as an integer. So when it goes to the comparison, the parser incorrectly believes the comparison to be between two known integers, which is a much simpler and faster comparison than having to check for type and convert something to a double if necessary.
This will be fixed in svn shortly. See ticket:126
Matt