taskSpawn 函数的使用问题

billy123456 2014-05-11 10:00:25
int taskSpawn
(
char *name, /*你要创建的任务名:比如说task1,在Shell下可以用命令:i 来查看当前系统中所有的任务*/
int priority, /*任务优先级,*/
int options, /*一般为0*/
int stackSize, /* 需要申请堆栈的大小*/
FUNCPTR entryPt, /*回调函数,*/
int arg1, /*传递给处理任务回调函数所需要的参数*/
int arg2,
int arg3,
int arg4,
int arg5,
int arg6,
int arg7,
int arg8,
int arg9,
int arg10
)

typedef struct
{
}Stype;
typedef Stype *pStype;
如果发起一个任务
void function(pStype Sty)
{
}
那么taskSpawn 中的参数 arg1 应怎么样写啊?一个结构体指针吗?
...全文
3021 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
紫神 2015-01-03
  • 打赏
  • 举报
回复
转化为int类型再传,传入后转回来, int指针也是4字节。。。。
i80428048 2015-01-01
  • 打赏
  • 举报
回复
/*****************/
typedef  struct
{
}Stype;
typedef  Stype  *pStype;

void function(pStype   Sty)
{
}
pStype arg;

taskSpawn ("tTest", 101, 0, 10000, function, arg,0,0,0,0,0,0,0,0,0)/*其余填零*/
woquNOKIA 2014-11-18
  • 打赏
  • 举报
回复
不用的就用0
「已注销」 2014-07-01
  • 打赏
  • 举报
回复
一般情况下,填0就可以了。
  • 打赏
  • 举报
回复
引用 vxworks6.8文档 的回复:
The arguments to taskSpawn( ) are the new task’s name (an ASCII string), the task’s priority, an options word, the stack size, the main routine address, and 10 arguments to be passed to the main routine as startup parameters: id = taskSpawn ( name, priority, options, stacksize, main, arg1, …arg10 );

/*Example 7-6 POSIX Unnamed Semaphores*/
/*
* This example uses unnamed semaphores to synchronize an action between the
* calling task and a task that it spawns (tSyncTask). To run from the shell,
* spawn as a task:
*
* -> sp unnameSem
*/
/* includes */
#include <vxWorks.h>
#include <semaphore.h>
/* forward declarations */
void syncTask (sem_t * pSem);
/************************************************************************
* unnameSem - test case for unamed semaphores
*
* This routine tests unamed semaphores.
*
* RETURNS: N/A
*
* ERRNOS: N/A
*/
void unnameSem (void)
{
sem_t * pSem;
/* reserve memory for semaphore */
pSem = (sem_t *) malloc (sizeof (sem_t));
if (pSem == NULL)
{
printf ("pSem allocation failed\n");
return;
}
/* initialize semaphore to unavailable */
if (sem_init (pSem, 0, 0) == -1)
{
printf ("unnameSem: sem_init failed\n");
free ((char *) pSem);
return;
}
/* create sync task */
printf ("unnameSem: spawning task...\n");
if (taskSpawn ("tSyncTask", 90, 0, 2000, syncTask, pSem) == ERROR)
{
printf ("Failed to spawn tSyncTask\n");
sem_destroy (pSem);
free ((char *) pSem);
return;
}
/* do something useful to synchronize with syncTask */
/* unlock sem */
printf ("unnameSem: posting semaphore - synchronizing action\n");
if (sem_post (pSem) == -1)
{
printf ("unnameSem: posting semaphore failed\n");
sem_destroy (pSem);
free ((char *) pSem);
return;
}
/* all done - destroy semaphore */
if (sem_destroy (pSem) == -1)
{
printf ("unnameSem: sem_destroy failed\n");
return;
}
free ((char *) pSem);
}
void syncTask
(
sem_t * pSem
)
{
/* wait for synchronization from unnameSem */
if (sem_wait (pSem) == -1)
{
printf ("syncTask: sem_wait failed \n");
return;
}
else
printf ("syncTask: sem locked; doing sync’ed action...\n");
/* do something useful here */
}
以上是文档中的例子
  • 打赏
  • 举报
回复
理解成entryPt的参数就对了。如果entryPt不需要参数,那写0就好了。
loopback_2012 2014-05-12
  • 打赏
  • 举报
回复
有啥参数就填什么,没有就不填,找个例子看下你就明白了

2,179

社区成员

发帖
与我相关
我的任务
社区描述
xworks是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统。
社区管理员
  • VxWorks开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧