Enable the _ERROR5_
macro in the application source file linux_test_application.c
and disable _ERROR3_
and _ERROR6_
as shown below.
//#define _ERROR3_
#define _ERROR5_
//#define _ERROR6_
The goal of multithread application debugging is to make the application thread-safe. You need to debug the application and identify the locations to protect read/write operations.
Under
FLOW
, highlight thelinux_test_app
, and Build.Under
FLOW
, highlight thelinux_test_app
, and Debug to launch a Launch Configuration.Select, the Target Connection; either
physical_zcu102
, orqemu_zcu102
and the Work Directory to /home/petalinux`
The code stops at the program entry. There are various debugging techniques such as breakpoints, stepping, and so on to identify the data that must be protected. This example will use the breakpoint inside thread function.
Put a breakpoint at below two lines.
printf("\n Job %d started\n", counter); ....... ....... printf("\n Job %d finished\n", counter);
Click Resume and check the Job ID printed in the console. Here, the job to be done is not thread-safe.
Open the Variables view to track the counter variable value.
Use a synchronization mechanism (mutex, for example) to ensure that two or more concurrent threads do not simultaneously execute read/writes.
Uncomment the mutex code lines listed below from the application to make it thread-safe.
............................ ............................ #ifdef _ERROR5_ void* doSomeThing(void *arg) { // pthread_mutex_lock(&lock); ................. ................. // pthread_mutex_unlock(&lock); ................. } #endif ............................ ............................ #ifdef _ERROR5_ /* if (pthread_mutex_init(&lock, NULL) != 0) { printf("\n mutex init failed\n"); return 1; } */ ............... ............... ............... // pthread_mutex_destroy(&lock);
Rebuild the application.
Relaunch the
Launch Configuration
Observe the output.