Error lower task is stopped when higher task is delayed

Hi everyone, I hope someone will help me with my problem. I’m using RTOS window port to simulate. I don’t know why my lower priority task is stopped when the higher priority task is delayed. Here is my code
This is code for task 1(priority = 1)

void vTaskFunction(void *pvParameter) {
	char *pcTaskName;
	pcTaskName = (char*)pvParameter;
	for (;;) {
		printf("%s  count = %d \n", pcTaskName,count++);
	}
		
}

this is code for task 2(priority = 2):

void vEventFunction(void *pvParameter) {
	char *pcTaskName;
	pcTaskName = (char*)pvParameter;
	for (;;) {
		printf("%s \n", pcTaskName);
		vTaskDelay(10 / portTICK_PERIOD_MS);
	}
}

This is what I have in main:

static const char * pcTextForTask1 = " Task 1 is running ";
		static const char * pcTextForTask2 = " Task 2 is running ";

		xTaskCreate(vTaskFunction, " Task 1", 1000,
			(void *)pcTextForTask1, 1, NULL);
		
		xTaskCreate(vEventFunction, " Task 2", 1000,
			(void *)pcTextForTask2, 2, NULL);
		
		vTaskStartScheduler();

This is my output:

When task2 is delayed, task1 should run through, but it doesn’t, it loop about 40 times and stop. Please help me

You cannot make rapid windows IO system calls, such as printf(), from tasks in that way as Windows with Block threads FreeRTOS thinks it has control over. Try replacing the printf() calls with simple variable increments to see if that fixes the problem.

1 Like

Could it be thar the delay factor in task 2 evaluates to 1? If so, change it so that the task delays for at least one tick.

1 Like

Thank you so much for your answer, it really fixes all my problems. That takes me a night for stressfull