(
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 应怎么样写啊?一个结构体指针吗?
9 个解决方案
#1
有啥参数就填什么,没有就不填,找个例子看下你就明白了
#2
#3
理解成entryPt的参数就对了。如果entryPt不需要参数,那写0就好了。
#4
/*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 */
}
以上是文档中的例子
#5
一般情况下,填0就可以了。
#6
不用的就用0
#7
#8
/*****************/
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)/*其余填零*/
#9
转化为int类型再传,传入后转回来,
int指针也是4字节。。。。
int指针也是4字节。。。。
#1
有啥参数就填什么,没有就不填,找个例子看下你就明白了
#2
#3
理解成entryPt的参数就对了。如果entryPt不需要参数,那写0就好了。
#4
/*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 */
}
以上是文档中的例子
#5
一般情况下,填0就可以了。
#6
不用的就用0
#7
#8
/*****************/
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)/*其余填零*/
#9
转化为int类型再传,传入后转回来,
int指针也是4字节。。。。
int指针也是4字节。。。。