0% found this document useful (0 votes)
4 views3 pages

Attachment 2 12

The document outlines a multithreaded sorting process for an integer list read from 'IntegerList.txt'. It details steps for dividing the list into sublists, sorting them with separate threads, merging the sorted sublists, and finally outputting the sorted list to 'SortedIntegerList.txt'. The input format consists of unique positive integers, and the document provides examples for clarity.

Uploaded by

Hanzy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Attachment 2 12

The document outlines a multithreaded sorting process for an integer list read from 'IntegerList.txt'. It details steps for dividing the list into sublists, sorting them with separate threads, merging the sorted sublists, and finally outputting the sorted list to 'SortedIntegerList.txt'. The input format consists of unique positive integers, and the document provides examples for clarity.

Uploaded by

Hanzy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Multithread Sorting

• Step 1: Read original integer list from “IntegerList.txt”

• Step 2: Divide the original integer list into two sublists

• Step 3: Create two threads that sort sublists independently

• Step 4: Wait for two threads to finish sorting

• Step 5: Create a thread that merges two sorted sublists into one sorted

integer list

• Step 6: Output the sorted list into “SortedIntegerList.txt”

Reading integer List

• File Name: “IntegerList.txt”

• Format: Positive unique integers in range [1,999], which are seperated by

commas.

• Total Number of Integers: At most 500

• Sample Input: “7,12,19,3,18,4,2,6,15,8”

Dividing integer List

• Dividing the integer list into two sublists evenly

• Sample Input: “7,12,19,3,18,4,2,6,15,8”

• Sample list: [7,12,19,3,18,4,2,6,15,8]

• Sample sublists: [7,12,19,3,18] [4,2,6,15,8]

• Sublist1: starting_index = 0; ending_index = 4

• Sublist2: starting_index = 5; ending_index = 9

• Special case: length of integer list is odd


• The integer in the middle of the integer list should be assigned to

one of the sublists

• Sample Input: “7,12,19,3,18,99,4,2,6,15,8”

• Sample sublists: [7,12,19,3,18,99] [4,2,6,15,8]

• Sublist1: starting_index = 0; ending_index = 5

• Sublist2: starting_index = 6; ending_index = 10

Creating and waiting sorting threads

• pthread_create(&tid_x, attr, sorter, data_x );

• tid_x: pthread_t, the pointer to the thread to be start

• attr: pthread_attr_t, attributes of thread

• If attr is NULL, the default attributes are used

• sorter: the sorting function implemented to sort sublist

• data_x: parameters for thread to process function sorter()

• pthread_join(tid_x,NULL);

• Waiting for thread tid_x finish

• Sample integer list: [7,12,19,3,18,4,2,6,15,8]

• Integer list after sorting threads: [3,7,12,18,19, 2,4,6,8,15]

• Creating merging thread with pthread_create(&tid3, attr, merger, data3 );

• Waiting for merging thread with pthread_join(tid3,NULL);

• Sample integer list: [3,7,12,18,19, 2,4,6,8,15]

• Integer list after merging thread is finished: [2,3,4,6,7,8,12,15,18,19]

Output sorted integers


• File name: SortedIntegerList.txt

• Format: Positive unique integers in range [1,999], which are separated by

commas.

• Sample output: “2,3,4,6,7,8,12,15,18,19”

You might also like