Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

In multithreading, 1 thread is stuck in between

Posted by pradnya123 on July 4, 2017

Hello, Im working with STM 32 controller. Using freeRTOS. I have created 4 threads out of which 2 are using same semaphore while other using different semaphores. It works fine for 10 to 12 hours but after that 1 thread is stuck while other 3 are in running state. Also if i resume this thread in some other function it is restarted. but what is reason to get Hanged? Why is this issue. Is it related to Stack size cause I tried increaning stack size for Thread but No use.


In multithreading, 1 thread is stuck in between

Posted by hs2sf on July 4, 2017

Sounds like a deadlock bug / race condition in your code. I think you should double-check your semaphores maybe including the interrupt handling / ISRs presumably driving the sempahore signalling.


In multithreading, 1 thread is stuck in between

Posted by pradnya123 on July 4, 2017

If it is issue related to semaphore ,any task should be stuck. But in my case only one task is stuck. it has High priority and also semaphore used is dedicated to this thread only.


In multithreading, 1 thread is stuck in between

Posted by pradnya123 on July 4, 2017

I am using HAL function to creat a task. Memory is allocated internally in these functions. Do i need to release this memory manually? If yes how to do this?


In multithreading, 1 thread is stuck in between

Posted by rtel on July 4, 2017

Unfortunately your original post didn't give anywhere near enough information to provide any suggestions - since then talk about interrupt priorities, memory allocation and stack overflows are just guesses with no context and no reason as to why they might be being suggested.

First ensure you are using the most recent version of FreeRTOS (as the newer the version the more debugging assistance you will get through asserts()), then do the normal things suggested on this page: http://www.freertos.org/FAQHelp.html (ensure configASSERT() is defined, etc.).

If that doesn't help then try using the http://www.freertos.org/trace tool so you can actually see how your application is executing - it might not be how you think it is.

If that does not help I would then suggest cutting down your application to the bare minimum that shows this issue, then posting the code that shows how the semaphore is being used.


In multithreading, 1 thread is stuck in between

Posted by pradnya123 on July 5, 2017

Thank you for your support. After debugging i have found that issue is arrise in stack memory only. In thread which stuck i called function uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL ); to find out free stack. Here stack memory reaches 0 and thread stuck. Now i need to know can we clear Heap manually. If yes how to do it. Here is my Code patch: Im defining Thread using HAL function hence memory is allocated automatically . how to release it back

	 /* Create the fourth Thread */
	osThreadDef(SemaphoreThread4, GPRS_Thread, osPriorityHigh, 0, 1324);
	GPRSThread_Handle = osThreadCreate(osThread(SemaphoreThread4), (void *) osGPRSSemaphore);

void GPRSThread(void const *argument) { static unsigned char Onlyonce; osSemaphoreId semaphore = (osSemaphoreId) argument;

int response = 0;
UBaseType_t uxHighWaterMark;

uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL ); 

 for(;;)
 {
	  if (semaphore != NULL)
	  {
		/* Try to obtain the semaphore. */
		if(osSemaphoreWait(semaphore , 500) == osOK)
		{

             /* Application Code*/
            if(osSemaphoreRelease(semaphore) != osOK)
			{
				HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, 0); //(LD1_Pin);
							while (1) {
							}
			} 
			osDelay(10); 
		}//endsemaphorewait
	  }// end if semaphore != NULL
  }//end for

}


In multithreading, 1 thread is stuck in between

Posted by pradnya123 on July 5, 2017

Thank you for your support. After debugging i have found that issue is arrise in stack memory only. In thread which stuck i called function uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL ); to find out free stack. Here stack memory reaches 0 and thread stuck. Now i need to know can we clear Heap manually. If yes how to do it. Here is my Code patch: Im defining Thread using HAL function hence memory is allocated automatically . how to release it back

	 /* Create the fourth Thread */
	osThreadDef(SemaphoreThread4, GPRS_Thread, osPriorityHigh, 0, 1324);
	GPRSThread_Handle = osThreadCreate(osThread(SemaphoreThread4), (void *) osGPRSSemaphore);

void GPRSThread(void const *argument) { static unsigned char Onlyonce; osSemaphoreId semaphore = (osSemaphoreId) argument;

int response = 0;
UBaseType_t uxHighWaterMark;

uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL ); 

 for(;;)
 {
	  if (semaphore != NULL)
	  {
		/* Try to obtain the semaphore. */
		if(osSemaphoreWait(semaphore , 500) == osOK)
		{

             /* Application Code*/
            if(osSemaphoreRelease(semaphore) != osOK)
			{
				HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, 0); //(LD1_Pin);
							while (1) {
							}
			} 
			osDelay(10); 
		}//endsemaphorewait
	  }// end if semaphore != NULL
  }//end for

}


In multithreading, 1 thread is stuck in between

Posted by richarddamon on July 5, 2017

If you stack high water mark gets to 0 bytes free, you need to alloocate more stack to that task or make that task take less stack.


In multithreading, 1 thread is stuck in between

Posted by rtel on July 5, 2017

As Richard D said, you have run out of stack space (the high water mark shows no free stack) so need to increase that. I'm not sure what you mean by 'clear heap manually'.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS