Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists