Skip to content

Commit ec33069

Browse files
committed
Fix: TS_GetNewestFromThreadQueue working only for finite values
For TS_GetNewestFromThreadQueue the thread could only return finite values for the requested variable. Instead of using the finite/non-finite state of the read value itself for the decision of returning the value a flag variable was introduced that is set when any value was read. This allows also to send a NaN value from a thread. (Note: It is best to use a custom timeout_default of e.g. -1 then) TS_GetNewestFromThreadQueueMult already uses the logic with a flag variable and does not need a fix.
1 parent 61e4f2b commit ec33069

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Packages/MIES/MIES_ThreadsafeUtilities.ipf

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static Constant TS_ERROR_INVALID_TGID = 980 // Invalid Thread Group ID or
1919
/// Throws away anything else in the datafolder from the thread queue.
2020
Function TS_GetNewestFromThreadQueue(variable tgID, string varName, [variable timeout_default, variable timeout_tries])
2121

22-
variable var, err, i, timeout
22+
variable var, err, i, timeout, readValidVar
2323

2424
ASSERT_TS(!isEmpty(varName), "varName must not be empty")
2525

@@ -37,8 +37,6 @@ Function TS_GetNewestFromThreadQueue(variable tgID, string varName, [variable ti
3737
ASSERT(IsInteger(timeout_tries) && timeout_tries > 0, "Invalid timeout_tries")
3838
endif
3939

40-
var = NaN
41-
4240
for(i = 0; i < timeout_tries; i += 1)
4341
AssertOnAndClearRTError()
4442
DFREF dfr = ThreadGroupGetDFR(tgID, timeout); err = GetRTError(1)
@@ -49,7 +47,7 @@ Function TS_GetNewestFromThreadQueue(variable tgID, string varName, [variable ti
4947
endif
5048

5149
if(!DataFolderRefStatus(dfr))
52-
if(IsFinite(var))
50+
if(readValidVar)
5351
return var
5452
elseif(TS_ThreadGroupFinished(tgID))
5553
return NaN
@@ -66,7 +64,8 @@ Function TS_GetNewestFromThreadQueue(variable tgID, string varName, [variable ti
6664
ASSERT_TS(NVAR_Exists(var_thread), "Expected variable from thread does not exist: " + varName)
6765

6866
// overwrite old values
69-
var = var_thread
67+
var = var_thread
68+
readValidVar = 1
7069
endfor
7170

7271
return timeout_default

0 commit comments

Comments
 (0)