Welcome to the Most Reliable Essay writing Service Online

CMPSC473, Spring 2020 Concurrency Lab

by | May 22

IntroductionNote that the assignment is due at noon. Concurrent programming is hard – start early.A channel is a model for synchronization via message passing. Messages may be sent over a channel by athread (Sender) and other threads which have a reference to this channel can receive them (Receivers).A channel can have multiple senders and receivers referencing it at any point of time.Channels are used as a primitive to implement various other concurrent programming constructs. Forexample, channels are heavily used in Google’s Go programming language and are very usefulframeworks for high-level concurrent programming. In this lab you will be writing your own version of achannel which will be used to communicate among multiple clients. A client can either write onto thechannel or read from it. Keep in mind that multiple clients can read and write simultaneously from thechannel. You are encouraged to explore the design space creatively and implement a channel that iscorrect and not exceptionally slow or inefficient. Performance is not the main concern in this assignment(functionality is the main concern), but your implementation should avoid inefficient designs that sleepfor any fixed time or unnecessarily waste CPU time.There are multiple variations to channels, such as whether the send/receive is blocking or non-blocking.In blocking mode, receivers always block until there is data to receive, whereas in non-blocking mode,they simply return. Similarly, with senders, in blocking mode, if the buffer is full, senders wait until somereceiver has retrieved a value and there is available space in the buffer whereas in non-blocking mode,they simply leave without sending. In this lab, you will support both blocking and non-blockingsend/receive functions.Another variation to channels would be if a channel is buffered (i.e., channel buffer size > 0) orunbuffered (i.e., channel buffer size = 0). In the buffered case, the sender blocks only until the value hasbeen copied to the buffer. On the other hand, if the channel is unbuffered, the sender blocks until thereceiver has received the value. In this lab, you will only be responsible for supporting bufferedchannels. Supporting unbuffered channels is extra credit and is especially difficult when implementingselect. The amount of extra credit is really small for the amount and difficulty of work involved, andcorrectly implementing the unbuffered version for select is probably 2-3 times the work of the entirebuffered assignment.The only files you will be modifying are channel.c and channel.h and optionally linked_list.c andlinked_list.h. You should NOT make any changes in any file besides these four files. You will beimplementing the following functions, which are described in channel.c and channel.h:• channel_t* channel_create(size_t size)• enum channel_status channel_send(channel_t* channel, void* data)• enum channel_status channel_receive(channel_t* channel, void** data)• enum channel_status channel_non_blocking_send(channel_t* channel, void* data)• enum channel_status channel_non_blocking_receive(channel_t* channel, void** data)• enum channel_status channel_close(channel_t* channel)• enum channel_status channel_destroy(channel_t* channel)• enum channel_status channel_select(select_t* channel_list, size_t channel_count, size_t*selected_index)The enum channel_status is a named enumeration type that is defined in channel.h. Rather than usingan int, which can be any number, enumerations are integers that should match one of the definedvalues. For example, if you want to return that the function succeeded, you would just return SUCCESS.You are encouraged to define other (static) helper functions, structures, etc. to help structure the codein a better way.Support routinesThe buffer.c and buffer.h files contain the helper constructs for you to create and manage a bufferedchannel. These functions will help you separate the buffer management from the concurrency issues inyour channel code. Please note that these functions are NOT thread-safe. You are welcome to use anyof these functions, but you should not change them.• buffer_t* buffer_create(size_t capacity)Creates a buffer with the given capacity.• enum buffer_status buffer_add(buffer_t* buffer, void* data)Adds the value into the buffer. Returns BUFFER_SUCCESS if the buffer is not full and value wasadded. Returns BUFFER_ERROR otherwise.• enum buffer_status buffer_remove(buffer_t* buffer, void** data)Removes the value from the buffer in FIFO order and stores it in data. Returns BUFFER_SUCCESSif the buffer is not empty and a value was removed. Returns BUFFER_ERROR otherwise.• void buffer_free(buffer_t* buffer)Frees the memory allocated to the buffer.• size_t buffer_capacity(buffer_t* buffer)Returns the total capacity of the buffer.• size_t buffer_current_size(buffer_t* buffer)Returns the current number of elements in the buffer.We have also provided the optional interface for a linked list in linked_list.c and linked_list.h. You arewelcome to implement and use this interface in your code, but you are not required to implement it ifyou don’t want to use it. It is primarily provided to help you structure your code in a clean fashion if youwant to use linked lists in your code. Linked lists may NOT be needed depending on your design, so donot try to force it into your solution. You can add/change/remove any of the functions in linked_list.cand linked_list.h as you see fit.Programming rulesYou are not allowed to take any of the following approaches to complete the assignment:• Spinning in a polling loop to implement blocking calls• Sleeping for any fixed amount of time; instead, use cond_wait or sem_wait• Trying to change the timing of your code to hide bugs such as race conditions• Using global variables in your codeYou are only allowed to use the pthread library, the POSIX semaphore library, basic standard C libraryfunctions (e.g., malloc/free), and the provided code in the assignment for completing yourimplementation. If you think you need some library function, please contact the course staff todetermine the eligibility. You can find a reference/tutorial for the pthread library at:https://computing.llnl.gov/tutorials/pthreads/You can find a reference/tutorial for the POSIX semaphore library at:http://www.csc.villanova.edu/~mdamian/threads/posixsem.htmlLooking at documentation (e.g., for these libraries, for tools, etc.) is fine, but as stated in the academicintegrity policy, looking online for any hints about implementing channels is disallowed.Evaluation and testing your codeYou will receive zero points if:• You violate the academic integrity policy (sanctions can be greater than just a 0 for theassignment)• You break any of the programming rules• Your code does not compile/build• Your code crashes the grading script• You don’t show your partial work by periodically adding, committing, and pushing your code toGitHubYour code will be evaluated for correctness, properly handling synchronization, and ensuring it does notviolate any of the programming rules (e.g., do not spin or sleep for any period of time). We haveprovided many tests, but we reserve the right to add additional tests during the final grading, so you areresponsible for ensuring your code is correct, where a large part of correctness is ensuring you don’thave race conditions, deadlocks, or other synchronization bugs. To run the supplied test cases, simplyrun the following command in the project folder:make testmake test will compile your code in release mode and run the grade.py script, which runs a combinationof the following tests to autograde your assignment:• After running the make command in your project, two executable files will be created. Thedefault executable, channel, is used to run test cases in the normal mode. The test cases arelocated in test.c, and you can find the list of tests at the bottom of the file. If you want to run asingle test, run the following:./channel [test_case_name] [iters]where [test_case_name] is the test name and [iters] is the number of times to run the test. Ifyou do not provide a test name, all tests will be run. The default number of iterations is 1.• The other executable, channel_sanitize, will be used to help detect data races in your code. Itcan be used with any of the test cases by replacing ./channel with ./channel_sanitize../channel_sanitize [test_case_name] [iters]Any detected data races will be output to the terminal. You should implement code that doesnot generate any errors or warnings from the data race detector.• Valgrind is being used to check for memory leaks, report uses of uninitialized values, and detectmemory errors such as freeing a memory space more than once. To run a valgrind check byyourself, use the command:valgrind -v –leak-check=full ./channel [test_case_name] [iters]Note that channel_sanitize should not be run with valgrind as the tools do not behave welltogether. Only the channel executable should be used with valgrind. Valgrind will issuemessages about memory errors and leaks that it detects for you to fix them. You shouldimplement code that does not generate any valgrind errors or warnings.IMPORTANT: Note that any test FAILURE may result in the sanitizer or valgrind reporting thread leaksor memory leaks. This is expected since test failures will cause the test to prematurely end withoutcleaning up any threads or memory. Thus, you should first fix the test failure.HandinSimilar to the last assignment, we will be using GitHub for managing submissions, and you must showyour partial work by periodically adding, committing, and pushing your code to GitHub. This helps ussee your code if you ask any questions on Canvas (please include your GitHub username) and also helpsdeter academic integrity violations.Additionally, please input the desired commit number that you would like us to grade in the Canvasassignment. You can get the commit number from github.com. In your repository, click on the commitslink to the left above your files. Find the commit from the appropriate day/time that you wantcommitted. Click on the clipboard icon to copy the commit number. Note that this is a much longernumber than the displayed number. Paste your very long commit number and only your commit numberin this assignment submission textbox.Hints• Carefully read the output from the sanitizer and valgrind tools and think about what they’retrying to say. Usually, they’re printing call stacks to tell you which locations have race conditions,or which locations allocate some memory that was being accessed in the race condition, orwhich locations allocate some memory that is being leaked, etc. These tools are tremendouslyuseful, which is why we’ve set them up for you for this assignment.• While the tools are very useful, they are not perfect. Some race conditions are rare and don’tshow up all the time. A reasonable approach to debugging these race condition bugs is to try toidentify the symptoms of the bug and then read your code to see if you can figure out thesequence of events that caused the bug based on the symptoms.• Debugging with gdb is a useful way of getting information about what’s going on in your code.To compile your code in debug mode (to make it easier to debug with gdb), you can simply run:make debugIt is important to realize that when trying to find race conditions, the reproducibility of the racecondition often depends on the timing of events. As a result, sometimes, your race conditionmay only show up in non-debug (i.e., release) mode and may disappear when you run it indebug mode. Bugs may sometimes also disappear when running with gdb or if you add printstatements. Bugs that only show up some of the time are still bugs, and you should fix these.Do not try to change the timing to hide the bugs.• If your bug only shows up outside of gdb, one useful approach is to look at the core dump (if itcrashes). Here’s a link to a tutorial on how to get and use core dump files:http://yusufonlinux.blogspot.com/2010/11/debugging-core-using-gdb.html• If your bug only shows up outside of gdb and causes a deadlock (i.e., hangs forever), one usefulapproach is to attach gdb to the program after the fact. To do this, first run your program. Thenin another command prompt terminal run:ps auxThis will give you a listing of your running programs. Find your program and look at the PIDcolumn. Then within gdb (may require sudo) run:attachwhere you replace with the PID number that you got from ps aux. This will give you a gdbdebugging session just like if you had started the program with gdb.
The post CMPSC473, Spring 2020 Concurrency Lab appeared first on My Assignment Online.



The Service Is Okay. I won’t Complain

The writers on the website are courteous and the customer service responds quickly. My paper was handled well; They promised...

Writers here are very professional and are native British

Thanks a lot for helping me out with my PhD Thesis, Writers here are very professional and are native British!!

Jack, The United Kingdom

Very Very Helpful, and On time.

Very Very Helpful, and On time.

Adelio M, Spain

I scored complete A’s in 3 out of four courses

I scored complete A’s in 3 out of four courses

Anonymous, Illinoi Chicago

CLICK HERE  To order your paper

About Essaysmiths Assignment writing service

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for upto 20% off in their first Order. Our payment method is safe and secure.

 CLICK HERE to Order Your Assignment


Recently Posted Questions.

Order your Assignment today and save 15% with the discount code ESSAYHELP