# vTaskDelete From xTaskGenericCreate

**URL:** <https://forums.freertos.org/t/vtaskdelete-from-xtaskgenericcreate/3511>\
**Category:** Kernel\
**Created:** [March 31, 2014, 1:58am UTC](https://forums.freertos.org/t/vtaskdelete-from-xtaskgenericcreate/3511 "2014-03-31T01:58:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 31, 2014, 1:58am UTC](https://forums.freertos.org/t/vtaskdelete-from-xtaskgenericcreate/3511/1 "2014-03-31T01:58:41Z")

</div>

**[l4n4](https://sourceforge.net/u/l4n4/)** wrote on [Monday, March 31, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/9ba87ecb/#13d6):

Since the current vTaskDelete is only called when the Idle Task is running, I encounter some cases when my system is too busy to let the idle task run & do the clean-up. Currently I’m trying not to create/delete tasks too many times, but still hoping to add a way to handle it when it happens. I’m considering to add another call to vTaskDelete from xTaskGenericCreate. In this way, when the idle task have a chance to run, it still going to delete the task waiting for termination. But when the idle task has no chance, the next task create will do the actual clean-up. Any thoughts on this? Thanks.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [March 31, 2014, 2:23am UTC](https://forums.freertos.org/t/vtaskdelete-from-xtaskgenericcreate/3511/2 "2014-03-31T02:23:47Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, March 31, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/9ba87ecb/#8c12):

You could define a trace macro to insert the code you want into the task create function as follows (insert at the bottom of FreeRTOSConfig.h):

```

#define traceTASK_CREATE( x ) while( uxTasksDeleted > 0 ) prvCheckTasksWaitingTermination()

```

Note that would only be called after memory was allocated for the task being created.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 31, 2014, 3:16am UTC](https://forums.freertos.org/t/vtaskdelete-from-xtaskgenericcreate/3511/3 "2014-03-31T03:16:55Z")

</div>

**[l4n4](https://sourceforge.net/u/l4n4/)** wrote on [Monday, March 31, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/9ba87ecb/#8c12/15c4):

Ok. Any specific reason why the deletion should be done after the memory is allocated for the new task? Because if the system has a very limited memory, it might be useful to do clean-up before any allocation. Thanks again.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [March 31, 2014, 3:37am UTC](https://forums.freertos.org/t/vtaskdelete-from-xtaskgenericcreate/3511/4 "2014-03-31T03:37:42Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, March 31, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/9ba87ecb/#f4e6):

It does not have to be - that is just where the trace macro I suggested defining is called from. Doing what you want using a trace macro just prevents you from having to edit the source files.

Regards.

---

<div class="post-metadata">

**Author:** ![tlafleur](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tlafleur](https://forums.freertos.org/u/tlafleur)\
**Post date:** [March 31, 2014, 4:17am UTC](https://forums.freertos.org/t/vtaskdelete-from-xtaskgenericcreate/3511/5 "2014-03-31T04:17:50Z")

</div>

**[tlafleur](https://sourceforge.net/u/tlafleur/)** wrote on [Monday, March 31, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/9ba87ecb/#f4e6/0ce4):

In general terms, limited memory system should build static task. Ie: never delete a task.

~~\_/) `_/)` \_/) ``` \_/)~~  
Sent from my Phone

> On Mar 30, 2014, at 8:37 PM, “Real Time Engineers ltd.” [rtel@users.sf.net](mailto:rtel@users.sf.net) wrote:
> 
> It does not have to be - that is just where the trace macro I suggested defining is called from. Doing what you want using a trace macro just prevents you from having to edit the source files.
> 
> Regards.
> 
> vTaskDelete From xTaskGenericCreate
> 
> Sent from [sourceforge.net](http://sourceforge.net) because you indicated interest in [SourceForge.net: Log In to SourceForge.net](https://sourceforge.net/p/freertos/discussion/382005/)
> 
> To unsubscribe from further messages, please visit [SourceForge.net: Log In to SourceForge.net](https://sourceforge.net/auth/subscriptions/)

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 31, 2014, 5:29am UTC](https://forums.freertos.org/t/vtaskdelete-from-xtaskgenericcreate/3511/6 "2014-03-31T05:29:33Z")

</div>

**[l4n4](https://sourceforge.net/u/l4n4/)** wrote on [Monday, March 31, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/9ba87ecb/#fb99):

Got it. Thanks.
