Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

C/C++代写 | COSC 1114 Programming Assignment 1

C/C++代写 | COSC 1114 Programming Assignment 1


1. Overview

In this assignment, you must write C/C++ code to implement a classic concurrency problem. Concurrency means “at the
same time” so each of these problems involve some level of simultaneous processing. The code must use system calls to
implement multi-threading to code the problems.

2. Learning Outcomes

This assessment relates to all the learning outcomes of the course which are:

• Summarise the full range of considerations in the design of file systems, summarise
techniques for achieving synchronisation in an operation system,

• Compare and contrast the common algorithms used for both pre-emptive and non-pre-
emptive scheduling of tasks in operating systems, such a priority, performance comparison,
and fair-share schemes. Contrast kernel and user mode in an operating system

3. Assessment details

You must implement two of five classic concurrency problems. While these problems have strange names like “Dining
Philosophers” and “Sleeping Barber” they represent real problems you may face in your programming career that you
may need to solve. You will learn from implementing a solution how to solve problems of concurrency.
In the process, you will come to understand the problems of debugging multi-threaded code.

Your solution to the problem you choose must not use busy waiting, which is where a program sits in a tight loop until
some condition is met as this wastes CPU time. Instead, you must have each thread sleep until a condition is met (use a
condition variable), wake up and do some processing and then perhaps signal other threads that the job has been done.

Please ensure sufficient output so that it is clear when your program performs any actions such as adding to an array,
locking a lock, etc.

You should ensure in your design of the program that you only share between threads the minimum state (variables)
possible as the more information that is shared the more likely there is to be a conflict (deadlocks, race conditions, etc).

Please see the courseware material for more detail on these problems. If your algorithm requires randomness, you should
ensure you seed the random number generator correctly.

To ease marking of your assignment, you must call your executable “simulation” and there must not be any subfolders in
the submitted zip file. All files must be in the root of the zip file.


Your solution must be written in C / c++ and you must supply a makefile that builds your solution incrementally and then
links it together. If you are feeling a big rusty about Makefiles or have not used them before, we recommend going
through the following tutorial:

Compiler Settings

Please note that as a minimum you must use the -Wall flag to generate warnings. You may use any supported c++ compiler
on the server – if you wish to use a standard above c++11 on the server with g++ you will need to use the scl command,
scl enable devtoolset-9 bash
Note: if you use a shell other than bash you can replace bash with your own preference.

Graceful Exit

Regardless of the problem you choose to implement, you will need to gracefully exit your simulation at the end of ten
seconds. Use the following method to do this: once you have launched all the required threads from main, call the sleep
function, to specify sleep for ten seconds. Once the sleep function finishes, change the value of a global variable to
indicate that all the threads should exit.


The solution you submit will ideally be as bug-free as possible including free of memory bugs. Your markers will mark
your submission on the titan/jupiter/saturn servers provided by the university and we will use the tool “valgrind” to test
that your program is memory correct (no invalid access to memory and all memory freed) and as such you should check
your program on titan before submission with this tool. The following command:
valgrind –track-origins=yes –leak-check=full –show-leak-kinds=all ./simulation
Will run your program with valgrind. Please note that in this case the name of the executable produced by compilation
of your program is ‘executable’, but it can be named whatever you like – just make it a sensible name, given the task
you are implementing.
Allowed Concurrency Functions

For the concurrency part of the assignment, you must limit yourself to the following functions:

• pthread_create
• pthread_join
• pthread_detach
• pthread_mutex_init
• pthread_mutex_destroy
• pthread_mutex_trylock
• pthread_mutex_lock
• pthread_cond_wait
• pthread_cond_signal
• pthread_cond_init
• you may also need the pthread_mutexattr_* functions

This list is not exhaustive and so if you are unsure, please ask on the discussion board about the function you wish to

Please note that in practice beyond this course, you would use higher-level c++ functions that call these functions but
part of what you are learning here is the underlying calls that are made as part of managing concurrency. That is, part
of what you are learning is to apply the theory that you learn in tutorials to practical problems.