Error 2: Multithread Application Debug - 2024.1 English

Vitis Tutorials: Embedded Software (XD260)

Document ID
XD260
Release Date
2024-06-19
Version
2024.1 English

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.

  1. Under FLOW, highlight the linux_test_app, and Build.

  2. Under FLOW, highlight the linux_test_app, and Debug to launch a Launch Configuration.

  3. Select, the Target Connection; either physical_zcu102, or qemu_zcu102 and the Work Directory to /home/petalinux`

../../../../_images/launch_config1.PNG

  1. 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.

  2. Put a breakpoint at below two lines.

    printf("\n Job %d started\n", counter);
    .......
    .......
    printf("\n Job %d finished\n", counter);
    
  3. Click Resume and check the Job ID printed in the console. Here, the job to be done is not thread-safe.

  4. Open the Variables view to track the counter variable value.

  5. Use a synchronization mechanism (mutex, for example) to ensure that two or more concurrent threads do not simultaneously execute read/writes.

  6. 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);
    
  7. Rebuild the application.

  8. Relaunch the Launch Configuration

  9. Observe the output.