How to debug multi-threading problems

OP (Company: Mehraris) #5527307
Hi everyone.

we had performed a project with discovery f746 board that within it 
there just was a GUI task to run emwin functions.

Another functions(such as reading and writing in sd card by fatfs , usb, 
spi and stuff) were placed in the routines of Buttons.

After several times the process of USB (writing in USB flash memory) was 
ran ,

the running process stuck in RTOS's functions.

After that we decided to add another thread for USB In such a way that, 
after pressing related button ,a message is sent to this thread.

At the first it works fine but after several times running this thread, 
mkdir function (for creating a folder in USB flash memory) returns 
FR_NOT_ENOUGH_CORE value and the program stops running.

For resolving this problem we increased stack and heap size and memory 
that is assigned to the thread but it didn't affect.

In new version of our project we just added a new thread and the routine 
that was placed in Notification sent by related button was moved into 
new thread and another sections of projects haven't changed.

In old version of project that there just was one thread , mkdir 
function never had returned FR_NOT_ENOUGH_CORE value.

It seems this problem is related to multi threading but we don't know 
how to find out running process and fix problem.

Could anyone help us to resolve this problem?

We'll appreciate your suggestions.
Guest #5527381
Hi,

can you monitor the memory consumption of the threads? For me this 
sounds like a memory leak. (I.e. the thread allocates new memory every 
time it runs without freeing it afterwards.)

Best regards,
 Martin L.
Guest #5527440
Well, many external devices are to be considered a resource, and thus 
can only be accessed by one thread at the time. Protect them with a 
semaphore.
OP (Company: Mehraris) #5528314
Hi Martin.

Thanks for your reply.
Actually i don't know how to monitor the memory consumption of the 
thread and i don't know if there is a function to free the memory 
allocated to thread.
(Company: CETPA) #5600779
Above links broken, So, you can use Debugging Programs with Multiple 
Threads. When dealing with debugging multi-threaded application, it is 
better not to use standard breakpoints that suspend just the thread 
where the breakpoint is set. Defining a standard breakpoint in your 
application, will only break the related thread. The other threads will 
be still running. For more visit at this link
https://stackoverflow.com/questions/1695268/multi-threaded-debugging-tutorial-for-gdb-and-c

Reply

A question of your own? This thread is over 8 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.