我正在尝试使用c进行睡眠理发师练习,但我无法弄清楚出了什么问题。请问有人这么友好地用外行术语解释我,我需要怎么做才能解决它。我不断收到此消息:
app_main.c,第72行:错误:无效值未忽略,因为它应该被忽略
app_main.c,第73行:错误:无效值未忽略,因为它应该被忽略
#define TASK0_PIN 0x80
INT8U err;
INT8U err2;
void Task0(void *dptr)
{
int value = OSSemPend(Barber,1,err); //aquire semaphore to perform barber
int value2 = OSSemPend(FreeSeats,1,err2);
那是问题所在。您可以在下面看到整个代码。
/*
**********************************************************
* uCOSII example 0
*
* uCOS uses prioritized preemptive scheduling.
*
* This example program contains 2 tasks:
* Task0 has lower priority (5) and can be preempted by task1.
* Task1 has higher priority (3).
**********************************************************
*/
#include "ucos_ii.h"
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
OS_EVENT *Barber;
OS_EVENT *FreeSeats;
int Customers;
//int Barber;
//int FreeSeats; //total number of seats
int Ready;
int Ready2;
int value;
int value2;
OS_STK Task0Stk[TASK0_STK_SIZE] __attribute__ ((section (".bss.stacks")));
OS_STK Task1Stk[TASK1_STK_SIZE] __attribute__ ((section (".bss.stacks")));
OS_STK Task2Stk[TASK2_STK_SIZE] __attribute__ ((section (".bss.stacks")));
int status;
void Task0(void *objdata);
void Task1(void *objdata);
void Task2(void *objdata);
int main(void)
{
OSInit();
status=OSTaskCreate(Task0,(void *)NULL,(OS_STK *)&Task0Stk[TASK0_STK_SIZE - 1], TASK0_PRIO);
status=OSTaskCreate(Task1,(void *)NULL,(OS_STK *)&Task1Stk[TASK1_STK_SIZE - 1], TASK1_PRIO);
status=OSTaskCreate(Task2,(void *)NULL,(OS_STK *)&Task2Stk[TASK2_STK_SIZE - 1], TASK2_PRIO);
Customers = 0;
Barber = OSSemCreate(1); //total nro of barbers
FreeSeats = OSSemCreate(2); //total number of seats
Ready= OSSemPost(Barber); // release semaphore
Ready2= OSSemPost(FreeSeats);
OSStart(); //OSStart never returns
return 0;
}
//------------------------------------------------------------------
// Task0 toggles pin PD7 every 3. OS tick (=3 msec with default tick 1 msec)
//------------------------------------------------------------------
#define TASK0_PIN 0x80
INT8U err;
INT8U err2;
void Task0(void *dptr)
{
//||
value = OSSemPend(Barber,1,err); //aquire semaphore to perform barber
value2 = OSSemPend(FreeSeats,1,err2);
if (value<1 || value2<1 )//if barber or seat are not available then wait
{
OSTimeDly(3);
}
else
{
DDRD|=TASK0_PIN;
for (;;) {
PORTD^=TASK0_PIN;
OSTimeDly(3); //wait 3 msec
Ready; //increment the semaphore and remove the task with highest priority from list and make it ready to run
Ready2;
}
}
}
//------------------------------------------------------------------
// Task0 toggles pin PD6 every OS tick (default 1 msec)
//------------------------------------------------------------------
#define TASK1_PIN 0x40
void Task1(void *dptr)
{
Customers +1;
if (FreeSeats >= 2)
{
FreeSeats -2;
dptr=dptr;
DDRD|=TASK1_PIN;
for (;;) {
PORTD^=TASK1_PIN;
FreeSeats +2;
Customers -1;
OSTimeDly(1); //wait 1 system tick
}
}
else
{
OSTimeDly(3);
Task1;
}
}
//------------------------------------------------------------------
// Task2 toggles pin PD6 every OS tick (default 1 msec)
//------------------------------------------------------------------
#define TASK2_PIN 0x20
void Task2(void *dptr)
{
Customers +1;
if (FreeSeats >= 2)
{
FreeSeats -2;
dptr=dptr;
DDRD|=TASK2_PIN;
for (;;) {
PORTD^=TASK2_PIN;
FreeSeats +2;
Customers -1;
OSTimeDly(2); //wait 1 system tick
}
}
else
{
OSTimeDly(3);
Task2;
}
}
最佳答案
OSSemPend返回void,并且您将返回的值分配给value
和value2
好像你要
OSSemPend(Barber,1,&err); //aquire semaphore to perform barber
OSSemPend(FreeSeats,1,&err2);
if (err != 0 || err2 != 0 )//if barber or seat are not available then wait
还是要使用
value = OSSemPend(Barber,1);
value2 = OSSemPend(FreeSeats,1,);
关于c - sleep 理发师OSSEMPEND(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13613568/