BEST代写-线上编程学术专家

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

C语言代写|CMPSC 473 Project 3 Channels in the C language

C语言代写|CMPSC 473 Project 3 Channels in the C language

本次美国代写是一个C语言通道的assignment

Main Project Code

Please get the code and create your group, similar to Projects 1-2 by following this link:

https://classroom.github.com/a/CRFf9Uo2

Note that groups for Project 3 are different, you must specify tgroup rather than group/sgroup when
creating or joining github groups to properly distinguish with Project 1-2 groups. This is very important
to avoid any confusion with Project 1-2 groups! Any repositories that do not conform to this naming
convention will be deleted

Extra Credit (Only)

Please use the following link to create a separate repository for extra credit only (if you completed the
extra credit part). Note that it is NOT for the main part of the project even if you are working alone, you
still must create and use the link for one-person groups above! Only extra credit part will be evaluated
and graded for the link below. Each partner must work individually for the extra credit part!

https://classroom.github.com/a/aCEPX0er

Introduction

Note that the concurrent programming is hard – start early.

A channel is a model for synchronization via message passing. Messages may be sent over a channel by a
thread (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. For
example, channels are heavily used in Google’s Go programming language and are very useful
frameworks for high-level concurrent programming. In this lab you will be writing your own version of a
channel which will be used to communicate among multiple clients. A client can either write onto the
channel or read from it. Keep in mind that multiple clients can read and write simultaneously from the
channel. You are encouraged to explore the design space creatively and implement a channel that is
correct 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 sleep for 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 some
receiver 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-blocking
send/receive functions.

Another variation to channels would be if a channel is buffered (i.e., channel buffer size > 0) or
unbuffered (i.e., channel buffer size = 0). In the buffered case, the sender blocks only until the value has
been copied to the buffer. On the other hand, if the channel is unbuffered, the sender blocks until the
receiver has received the value. In this lab, you will only be responsible for supporting buffered
channels. Supporting unbuffered channels is extra credit and is especially difficult when implementing
select. The amount of extra credit is really small for the amount and difficulty of work involved, and
correctly implementing the unbuffered version for select is probably 2-3 times the work of the entire
buffered assignment. The extra credit part will have to be done in a separate repository individually.

The only files you will be modifying are channel.c and channel.h and optionally linked_list.c and
linked_list.h. You should NOT make any changes in any file besides these four files. You will be
implementing the following functions, which are described in channel.c and channel.h:

• chan_t* channel_create(size_t size)
• enum chan_status channel_send(chan_t* channel, void* data, bool blocking)
• enum chan_status channel_receive(chan_t* channel, void** data, bool blocking)
• enum chan_status channel_close(chan_t* channel)
• enum chan_status channel_destroy(chan_t* channel)
• enum chan_status channel_select(size_t channel_count, select_t* channel_list, size_t*
selected_index)

The enum chan_status is a named enumeration type that is defined in channel.h. Rather than using an
int, which can be any number, enumerations are integers that should match one of the defined values.

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 code
in a better way.

Support routines

The buffer.c and buffer.h files contain the helper constructs for you to create and manage a buffered
channel. These functions will help you separate the buffer management from the concurrency issues in
your channel code. Please note that these functions are NOT thread-safe. You are welcome to use any
of these functions, but you should not change them.

• buffer_t* buffer_create(size_t capacity)
• Creates a buffer with the given capacity.
• bool buffer_add(void* data, buffer_t* buffer)
Adds the value into the buffer. Returns ‘true’ if the buffer is not full and value was added.
Returns ‘false’ otherwise.
• void* buffer_remove(buffer_t* buffer)
Removes the value from the buffer in FIFO order and returns it. Otherwise, returns
BUFFER_EMPTY (a special pointer value) if the buffer is empty and a value was not removed.
• 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.

bestdaixie

评论已关闭。