UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

11.5.6.  Concurrent application design (threads)

Work Plan

Very satisfied with your work, SAUCEM orders you to work in the definition of two concurrent applications: conc_odd_or_even_in_a_list and conc_prime_numbers with the following informal specification about them:

  1. Design a concurrent application to launch two threads that perform concurrent processing on a list. The first one has to count the odd numbers and the second number of even numbers. Both work on the following list of integers :

    struct integer_list{
     int int_data;
     struct integer_list* next;      
     };    

    Additionally, you have the following information:

    1. The program is to create a list with 4 elements for testing (3,4,5,7). With these values, the program would output:

      ./con_even_odd_in_list
      [Main] Threre are 3 even(s) and 1 odd(s).
      	    

    2. The main function is to create the list, allocate the threads, and wait for these end up to operate. The threads exit as they have processed a list.

    3. The solution should be safe (no deadlocks or race conditions). Nor you can use or a mutex and condition variables in your application.

  2. Another concurrent application design (conc_prime_process) requires you to calculate the number of primes that are in a fixed-size table: M. The algorithm implemented to ask whether a number (n) is prime is to know only divisible by 1 and by the same.

    1. In the laboratory, they have proposed that for each position of the array must launch POSIX thread. After completing all the main function will print all numbers, specifying if they are prime or not, one by one.

    2. As a starting point, you can use the following array: 1000331, 0, 3, 5, 7.