1.15 freertos 计数器生产和消费模型

osSemaphoreId_t myCountingSem01Handle;
const osSemaphoreAttr_t myCountingSem01_attributes = {
  .name = "myCountingSem01"
};

myCountingSem01Handle = osSemaphoreNew(5, 0, &myCountingSem01_attributes);

void StartTask02(void *argument)
{
  /* USER CODE BEGIN StartTask02 */
  /* Infinite loop */
//	stu_t s1;
  for(;;)
  {	  
	  printf("我生产了俩辆小汽车\r\n");
	  osSemaphoreRelease(myCountingSem01Handle);
	  osSemaphoreRelease(myCountingSem01Handle);
	  osDelay(1000);
  }
  /* USER CODE END StartTask02 */
}

/* USER CODE BEGIN Header_StartTask03 */
/**
* @brief Function implementing the myTask03 thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTask03 */
void StartTask03(void *argument)
{
  /* USER CODE BEGIN StartTask03 */
  /* Infinite loop */
  for(;;)
  {
	osSemaphoreAcquire(myCountingSem01Handle,osWaitForever);
	printf("我购买了一辆小汽车\r\n");

    osDelay(1);
		
  }
  /* USER CODE END StartTask03 */
}

1.15 freertos 计数器生产和消费模型_第1张图片

1.15 freertos 计数器生产和消费模型_第2张图片

你可能感兴趣的:(开发语言)