<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>spawn a method as a task (C++)</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/26740/spawn-a-method-as-a-task-c</link><description> 
Hello, 

 
I&amp;#39;m using RTX and I&amp;#39;m porting my C code tot C++. Now I have a
problem with os_tsk_create_user . I want to use a class method
as the function for os_tsk_create_user : 

 
 
Example::Example(void) 
{ 

 
 mExampleTask = os_tsk_create_user </description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: spawn a method as a task (C++)</title><link>https://community.arm.com/thread/139465?ContentTypeID=1</link><pubDate>Tue, 12 Jan 2010 03:15:28 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e3b9fde3-0ea3-4eec-bc5f-1edffa6afa79</guid><dc:creator>M D</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi Roland,&lt;/p&gt;

&lt;p&gt;
yes, I also solved with static methods for initialization but...
this is source of some concern. Something under the hood is going on
and could lead to other problems later... (?)&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spawn a method as a task (C++)</title><link>https://community.arm.com/thread/130584?ContentTypeID=1</link><pubDate>Tue, 12 Jan 2010 02:48:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:87b0aa20-c1f3-4226-b9c8-a5cfb2ce7d9f</guid><dc:creator>Roland Beuker</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello Marco,&lt;/p&gt;

&lt;p&gt;
I have similar problems with static variables... A work around
possibility is to initialize these statics from your main with a
static init() method...&lt;/p&gt;

&lt;p&gt;
I my own project I&amp;#39;ll try to remove all dynamic content (never use
new()). In this situation the the task start has to be moved from the
constructor to it&amp;#39;s own method (startTask()).&lt;/p&gt;

&lt;p&gt;
Regards,&lt;/p&gt;

&lt;p&gt;
Roland&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spawn a method as a task (C++)</title><link>https://community.arm.com/thread/125940?ContentTypeID=1</link><pubDate>Tue, 12 Jan 2010 02:34:01 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:203d1b03-b063-4579-9ed1-8a71357fc5f3</guid><dc:creator>M D</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi,&lt;/p&gt;

&lt;p&gt;
I&amp;#39;m also using singleton technique (each singleton is a wrapper
for a task) but I have a strange problem:&lt;/p&gt;

&lt;p&gt;
for SOME singleton classes (not all!) the mInstance static member
is not NULL when the main begins (even if they are all correctly
initialized like in the example above)&lt;br /&gt;
As a result, the returned pointer is meaningless and the exceution
goes into hardfault handler (even before creating the task, I have a
-&amp;gt;Setup() method to launch).&lt;br /&gt;
The linker map file seems ok, each one of them has allocated 4 bytes,
is of Data type and there are no overlapping variables.&lt;br /&gt;
Any idea ?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spawn a method as a task (C++)</title><link>https://community.arm.com/thread/115467?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2010 14:56:32 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ee265e9d-b7fd-4bac-bc1b-5673dad93e0f</guid><dc:creator>Roland Beuker</dc:creator><description>&lt;p&gt;&lt;p&gt;
Like this :&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;Display.h&lt;/b&gt;&lt;/p&gt;

&lt;pre&gt;
class Display
{
public:

  static Display *getInstance(void);

protected:

   Display(void);

private:

  static Display *mInstance;
  static void displayTaskEntry(Display *pDisplayPtr);

  OS_TID mDisplayTask;
  U64 mDisplayTaskStack[DISPLAY_TASK_STACK_SIZE];

  void displayTask (void);
};
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
&lt;b&gt;Display.cpp&lt;/b&gt;&lt;/p&gt;

&lt;pre&gt;
/*-----------------------------------------------------------*/

Display *Display::mInstance = NULL;

/*-----------------------------------------------------------*/

Display::Display(void)
{
  mDisplayTask = os_tsk_create_user_ex((void (*)(void *)) displayTaskEntry, DISPLAY_TASK_PRIORITY, mDisplayTaskStack, sizeof(mDisplayTaskStack), this);
}

/*-----------------------------------------------------------*/

Display *Display::getInstance()
{
  if (!mInstance)
  {
    mInstance = new Display();
  }

  return mInstance;
}

/*-----------------------------------------------------------*/

__task void Display::displayTaskEntry(Display *pDisplay)
{
  pDisplay-&amp;gt;displayTask();
}

/*-----------------------------------------------------------*/

void Display::displayTask (void)
{
  for (;;)
  {
    os_dly_wait (10);
  }
}

/*-----------------------------------------------------------*/
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spawn a method as a task (C++)</title><link>https://community.arm.com/thread/102025?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2010 13:46:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4cfe47c0-0fb7-49f0-a6ce-fd032e2743a8</guid><dc:creator>Roland Beuker</dc:creator><description>&lt;p&gt;&lt;p&gt;
Robert Thanks!&lt;/p&gt;

&lt;p&gt;
Instead of the global function I&amp;#39;ll use a static member variant
(to hold the object oriented idea ;-)&lt;/p&gt;

&lt;p&gt;
The object is created using the singleton pattern (with lazy
instantiation) so the OS is running before the call to tsk_create&lt;/p&gt;

&lt;p&gt;
Regards,&lt;/p&gt;

&lt;p&gt;
Roland&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spawn a method as a task (C++)</title><link>https://community.arm.com/thread/78027?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2010 07:30:52 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7691e5e0-d75f-4c7f-9aa8-765a243a1586</guid><dc:creator>Robet McNamara</dc:creator><description>&lt;p&gt;&lt;p&gt;
Global function&lt;/p&gt;

&lt;pre&gt;
void cpp_task_entry(Ctask_base *baseTask)
{
    baseTask-&amp;gt;run();
    os_tsk_delete_self();
}
&lt;/pre&gt;

&lt;p&gt;
To create task (maybe in constructor, but it is not wise to call
tsk_create before the OS is running) call
os_tsk_create_user_ex&lt;/p&gt;

&lt;pre&gt;
tid = os_tsk_create_user_ex( (void (*)(void *)) cpp_task_entry, prio, &amp;amp;stack, sizeof(stack), this);


&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spawn a method as a task (C++)</title><link>https://community.arm.com/thread/57531?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2010 02:37:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8d5f55c5-4b25-40e3-bbd8-34dc91972efd</guid><dc:creator>Roland Beuker</dc:creator><description>&lt;p&gt;&lt;p&gt;
example:&lt;/p&gt;

&lt;p&gt;
&lt;a href="http://www.xs4all.nl/~borkhuis/vxworks/vxw_pt5.html#5.9-F"&gt;www.xs4all.nl/.../vxw_pt5.html&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>