News:

  • June 25, 2026, 10:32:25 AM

Login with username, password and session length

Author Topic: Tasks calling tasks  (Read 9469 times)

Glennlee

  • Full Member
  • ***
  • Posts: 23
Tasks calling tasks
« on: July 18, 2014, 11:02:25 AM »
Hi Everyone.

I have written three tasks that work great.  I need to create a fourth task and I want to re-use one of the existing tasks by calling it from within my new task.  I will allow the calling task to continue, or exit the task depending on the results from the called task.

My question is:  will the calling task wait to complete its' code until the called task has completed?

The called task is a loop that scans a database for a matching part number.  It returns either the index of a match, or a bit that states "no match found".

If there is no match, then the calling task has an index pointing to an empty space at the end of the database.  It will then write the new entry and exit.

If the called task indicates a match, I trigger a pop-up screen and exit the task.

I await breathlessly for your reply!

Glenn

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6161
  • Yes Pinky, Do-more will control the world!
Re: Tasks calling tasks
« Reply #1 on: July 18, 2014, 11:10:03 AM »
Tasks are not subroutines and are not called or executed in-line. They are enabled and run independently in the execution order defined in the Project Browser.

If you are trying to do subroutine-style execution, the preferred way would be to use a Program block with stages to sequence the Task execution. In the Task execution stage put an ENTASK instruction, and then on the next rung use the .Done member of the Task structure to enable a JMP to the next stage.

We are actively developing function and subroutines, which are both called and executed in-line, and these will be a part of DmD 2.0 due out next year.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

plcnut

  • Hero Member
  • *****
  • Posts: 814
    • premiersi.com
Re: Tasks calling tasks
« Reply #2 on: July 18, 2014, 11:21:03 AM »
Like Bobo said, the best way is probably to use a program block as the supervisor... but... you can make it work...

Code: [Select]
------------------------------------ENTASK (MyTask)

REPEAT

YIELD

UNTIL (MyTask.done)

remaining code...

Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

plcnut

  • Hero Member
  • *****
  • Posts: 814
    • premiersi.com
Re: Tasks calling tasks
« Reply #3 on: July 18, 2014, 11:22:44 AM »
I hope I didn't scare you too bad there Bob... ;)
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6161
  • Yes Pinky, Do-more will control the world!
Re: Tasks calling tasks
« Reply #4 on: July 18, 2014, 11:39:52 AM »
I hope I didn't scare you too bad there Bob... ;)

Hmmm...hadn't thought of doing it that way, but that would work just fine.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO