Jump to content

Console in multi-thread environment


Rafael Zingler

Recommended Posts

Hi,

I´ve doubts about the console widget with in a project that uses FreeRTOS. There are calls to the gwinPrintf() function in more than one thread. When this function is called from a timer callback function and simultaneously in other thread, the console´s content is jumbled. Sometimes, even the characters are not correctly redrawn in such case.

Is this behavior expected?

Thanks.

Edited by Rafael Zingler
Link to comment
Share on other sites

Hello Rafael,

The characters being drawn incorrectly in the screen indicates that you didn't set GDISP_NEED_MULTITHREAD to TRUE which will make the entire GDISP API become thread safe.
The GWIN console widget itself is however not multi-thread safe so you have to protect access to it yourself. The solution depends on your application. You can either go with a classic producer/consumer where you have just one consumer (the sole thread that writes to the console) and multiple producers. Alternatively you can simply use the a mutex to protect access inside your application.
Note that we strongly recommend using the µGFX high-level API such as gfxMutexCreate() and similar to keep your application portable. They are simple wrappers (often just macros so no overhead) towards the corresponding FreeRTOS mutex API.

I hope that helps.

Link to comment
Share on other sites

Thanks, Joel.

 

The GDISP_NEED_MULTITHREAD option is already configured as TRUE in the gfxconf.h file.

For now, to solve the problem, I´ll implement the consumer/producer scheme to guarantee "serial" access to the console, with only the consumer accessing this widget. I´m going to replace, then, the gwinPrintf () calls with xQueueSend() calls, to send the desired messages to the console.

Thanks.

Edited by Rafael Zingler
Link to comment
Share on other sites

Jumbled text may be expected but characters not being drawn correctly is definitely not.

Characters are drawn by the gdisp layer either one by one or as a string. If GDISP_NEED_MULTITHREAD is TRUE is should be impossible to get character corruption.

Please check carefully exactly what is happenning.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...