请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:CC1352P7 您好
我使用的是 LP-CC1352P7-1。
我正在尝试在代码中创建几个线程。 将创建除一个线程之外的所有线程。
在下面的代码中创建的线程:
void B_taskCreate(void)
{
pthread_t thread;
pthread_attr_t attrs;
struct sched_param priParam;
int retc;
/* Initialize the attributes structure with default values */
pthread_attr_init(&attrs);
/* Set priority, detach state, and stack size attributes */
priParam.sched_priority = 5;
retc = pthread_attr_setschedparam(&attrs, &priParam);
retc |= pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
retc |= pthread_attr_setstacksize(&attrs, 1024);
if (retc != 0)
{
/* failed to set attributes */
while (1) {}
}
retc = pthread_create(&thread, &attrs, b_task, NULL);
if (retc != 0)
{
/* pthread_create() failed */
while (1) {}
}
retc = pthread_attr_destroy(&attrs);
}
未创建的代码是具有不同优先级和例程的相同代码:
void a_taskCreate(void)
{
pthread_t thread;
pthread_attr_t attrs;
struct sched_param priParam;
int retc;
/* Initialize the attributes structure with default values */
pthread_attr_init(&attrs);
/* Set priority, detach state, and stack size attributes */
priParam.sched_priority = A_TASK_PRIORITY; //priority 3
retc = pthread_attr_setschedparam(&attrs, &priParam);
retc |= pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
retc |= pthread_attr_setstacksize(&attrs, 1024);
if (retc != 0)
{
/* failed to set attributes */
while (1) {}
}
retc = pthread_create(&thread, &attrs, a_task, NULL);
if (retc != 0)
{
/* pthread_create() failed */
while (1) {}
}
retc = pthread_attr_destroy(&attrs);
}
在上面的代码中(不创建线程的代码)、下面一行的返回值为22:
retc = pthread_attr_setschedparam(&attrs, &priParam);
这可能是什么原因、如何纠正?
此致