Your Digital Media Has Never Looked So Good

 
greubel
Topic Author
Posts: 708
Joined: Wed Feb 10, 2010 4:21 pm

Task XML Blocks

Thu Dec 20, 2018 10:32 am

I assumed that the TASK which is spawned would be asynchronous. But that doesn't seem to be the case.
It looks like it is blocking ?????

Code in MAIN.BRS

   t = m.scene.findNode("mytask")
   for i=0 to 5
? "Main " i " before"
      t.Input = { data:i }
? "Main " i " after"
? " "
   end for

Code in TASK.XML

Sub Activate()
   x = m.top.Input.data
? "Task in = " x
   sleep(100)
? "Task exit after 100 milliseconds"
End Sub

RESULT

Main  0 before
Task in =  0
Task exit after 100 milliseconds
Main  0 after
 
Main  1 before
Task in =  1
Task exit after 100 milliseconds
Main  1 after
 
Main  2 before
Task in =  2
Task exit after 100 milliseconds
Main  2 after
 
Main  3 before
Task in =  3
Task exit after 100 milliseconds
Main  3 after
 
Main  4 before
Task in =  4
Task exit after 100 milliseconds
Main  4 after
 
Main  5 before
Task in =  5
Task exit after 100 milliseconds
Main  5 after




 
 
joetesta
Posts: 790
Joined: Wed Apr 20, 2011 11:48 am

Re: Task XML Blocks

Thu Dec 20, 2018 12:54 pm

My understanding (though don't hold me to it / correct me if I'm mistaken) is that the task blocks itself (because it operates on its own thread), but you could spin off 5 separate tasks asynchronously that don't block each other; use createObject in the brs / render thread to spin off new tasks of the same type.
aspiring
 
greubel
Topic Author
Posts: 708
Joined: Wed Feb 10, 2010 4:21 pm

Re: Task XML Blocks

Thu Dec 20, 2018 4:42 pm

I thought a TASK was like a fork, new activity.
What I have is, the main.brs routine triggers the TASK node. The TASK executes BUT the main doesn't get control back until the TASK completes.
You can this by the displays I provided.

Main  0 before
Task in =  0
Task exit after 100 milliseconds
Main  0 after
 
renojim
** Valued Community Member **
Posts: 3481
Joined: Mon Feb 15, 2010 1:35 pm

Re: Task XML Blocks

Thu Dec 20, 2018 7:59 pm

My understanding of how tasks operate is limited at best and I've only used the control field to start a task (setting it to "RUN").  I assume you're trying to use the third development use case:

  • A Task node observes its input <interface> fields using the port form of the ifSGNodeField observeField() method, and returns output data with each field change. In this case, the Task node acts like a continuous server.

So maybe there's an implied "wait for the output data" in this?  The documentation could be better.  I used two labels and an observeField in my task and in my main loop to "RUN" the task and then get its output when it finished.  The main loop is definitely not blocking (not that I'm doing anything useful while waiting).

-JT
 
greubel
Topic Author
Posts: 708
Joined: Wed Feb 10, 2010 4:21 pm

Re: Task XML Blocks

Fri Dec 21, 2018 11:19 am

I think I have it.
If you trigger the Task with the observed field, it will run synchronously. That is the main activity will block until the task completes.
if you set parameters in the node and then set the control to "run", it spawns a new thread and the main activity continues.
 
greubel
Topic Author
Posts: 708
Joined: Wed Feb 10, 2010 4:21 pm

Re: Task XML Blocks

Fri Dec 21, 2018 11:36 am

Anyone have an idea what "waitRelease", "syncRelease" and "sleepRelease " in the Task node are used for ?

Who is online

Users browsing this forum: No registered users and 2 guests