首页 > 其他分享 >CS-350 - Fundamentals of Computing Systems

CS-350 - Fundamentals of Computing Systems

时间:2024-12-08 16:55:54浏览次数:7  
标签:operations Computing Fundamentals image should client semaphore CS server

CS-350 - Fundamentals of Computing Systems

Homework Assignment #8 - BUILD

Due on November 14, 2024 — Late deadline: November 16, 2024 EoD at 11:59 pmProf. Renato Mancuso Renato Mancuso 1CS-350 - Fundamentals of Computing Systems::Homework Assignment #8 - BUILD Problem 1

BUILD Problem 1 We now have a server capable of performing non-trivial operations on images! All we have to do now is tomake the server multi-threaded. And yes, we already have the infrastructure to spawn multiple threads. Sowhat’s missing exactly?Output File: server_mimg.cOverview. As mentioned above, the main idea is to allow multple workers to perform operations on imagesin parallel. Everything you have developed in BUILD 6 will be reused, but we must make sure that whenmultiple worker threads are spawned, the correctness of the operations on the images is still guaranteed.But what could be jeopardizing the correctness of these operations? Let us consider a concrete case. Imaging

the following sequence of requests queued at the server: (1) Retrieve image A, (2) blur image A, (3) detectthe vertical edges of image A, and (4) send back the result of the operations performed on image A.With only one worker, the operations are carried out in this sequenceand the result sent back to the client isan image with the cumulative operations (2) and (3) correctly applied to the source image. With 2 workers(unless we fix our implementation) we could have worker #1 and #2 working in parallel on operations (1)and (2) with the result of the operations being some weird mix ofthe two operations.In this assignment, the goal is to allow safe multi-threading where the semantics of sequential operations onthe images is preserved even if multiple threads are spawned and operate in parallel. For this task, we willuse semaphores to perform inter-thread synchronization.

Design. One of the main problem that we have to solve is un-arbitrated access to shared data structures.

o verify that there is a problem unless we insert synchronization primitives accordingly, start with your (or

  1. my) solution for HW6, rename it appropriately, and enable spawning more than 1 worker threads.Then, run the following simple experiment. First, run the client to generate the sequence of operations listed

above with 1 worker thread and look carefully at the output report generated by the client:

./server_mimg -q 100 -w 1 2222 & ./client -I images/ -L 1:R:1:0,0:b:1:0,0:v:1:0,0:T:1:0 2222

You will notice that the first hash reported by the client (9f3363f0249c15163d52e60fd9544c31) is simply

the hash of the original test1.bmp image. The second (and last) hash reported by the client is the hash

(00e4fc4b9c7c71ee2ca3946053f78793) of the blur+vertical edge detection operations applied in sequence

to the image. However, if we increase the number of worker to 2, the final hash will be different! For instance,b5932c2bcb0a64121def911286c706e2, butmight be something else entirely on a different machine. Also in some cases, the server crashes entirely.To solve the problem, the cleanest way is to introduce semaphore-based synchronization between threads.In order to define a semaphore, you should use the type sem_t defined in semaphore.h. Before a semaphorecan be used, it must be initialized.

This can be done with the sem_init(sem_t * semaphore, int pshared, unsigned int init_value).Here, semaphore is pointer to the semaphore to be initialized, pshared can be set to 0, and init_value isa non-negative initialization value of the semaphore, following the semantics we have covered in class.Once your semaphore has been correctly initialized (make sure to check for the error value of the sem_init(...)

call!), the wait and signal operations can be performed over it, following the semantics we have discussedProblem 1 continued on next page. . . 2CS-350 - Fundamentals of Computing Systems::Homework Assignment #8 - BUILD Problem 1 (continued)in class. To wait on a semaphore, you must use the sem_wait(sem_t * semaphore) call; to signal on asemaphore, you must use the sem代写CS-350 - Fundamentals of Computing Systems _post(sem_t * semaphore).Shared Data Structures. Of course, the main question is what data structures must be protected?. Hereis a list of things that can be problematic, but your own implementation could be different, so try to mapthe statement below to your own code.

(1) Image Objects: One obvious place to start is to protect the image objects that are registered withthe server and upon which operations are requested by the client. We want to prevent different workerto simultaneously change the content of an image, so a good idea is to introduce one semaphore per eachregistered image! These must be created and/or initialized dynamically at image registration time.

(2) Image Registration Array: Another shared data structure is the global array of registered images.Concurrent operations over that array is not a good idea, so all thethreads will need to synchronize whetrying to access that shared data structure.

(3) Connection Socket: What? The connection socket has always been shared, so why is that a problemnow? The truth is that it has always been a problem, but we did not care because the responses fromthe workers to the client were always a one-shot send(...) operation. But now, there are cases where theserver follows a two-step approach in the protocol it follows with the client. For instance, when handling anIMG_RETRIEVE operation, a worker first provides a positive acknowledgment of completed request and thenthe payload of the image being retrieved. What if another worker starts sending other data while a retrieveoperation is in progress? Careful: the same goes for the parent when handling IMG_REGISTER operations.

(4) Request Queue and STDOUT Console: We already know that the shared request queue and the

shared STDOUT console require the use of semaphores to ensure correctness. Perhaps take inspiration from

the use of semaphores in those cases to handle the other shared data structures listed above.

Desired Output. The expected server output is pretty much what you already constructed in HW6. Hereis it summarized again for reference. You should print queue status dumps, rejection and completion notices.Queue status dumps and rejection notice are identical in format to HW5 and HW6. Once again, the queudump status is printed when any of the worker threads completes processing of any of the requests.Just like HW6, when a request successfully completes service, thethread ID of the worker thread that has

completed the request will need to be added at the beginning of the line following the format below. You canssign thread ID = (number of workers + 1) to the parent thread. If multiple worker threads are available to

process a pending request, any one of them (but only at most one!) can begin processing the next request.T<thread ID> R<req. ID>:<sent ts>,<img_op>,<overwrite>,<client img_id>,<server img_id>,<receipt ts>,<start ts>,<compl. ts>Here, <img_op> is a string representing the requested operation over an image. For instance, if the operationwas IMG_REGISTER, then the server should output the string “IMG REGISTER” (no quotes) for this field.<overwrite> should just be 0 or 1, depending on what the client requested. <client img_id> should bethe image ID for which the client has requested an operation. If the server is ignoring any of these valuesin the response, set these fields to 0. Finally, <server img_id> should report the image ID on which theserver has performed the operation requested by the client. Recall that this might be different from what

sent by the client if overwrite = 0 in the client’s request, but it must be the same if overwrite = 1.Additional Help. You might have noticed, from the commands recommended above, that the client (v4.2)now allows you to define a script of image operation requests. This is useful to test the correctness of yourserver under a controlled workload.To use this feature, you should still provide the path to the folder containing the test images using the-I <path to images folder> parameter. Next, you should also provide the -L <images request script>parameter, where the <images request script> is a comma-separated list of image operations with thefollowing formatProblem 1 continued on next page. . . 3CS-350 - Fundamentals of Computing Systems::Homework Assignment #8 - BUILD Problem 1 (continued)<time to next operation>:<opcode char>:<overwrite>:<image ID>.Here, <time to next operation> is a number of seconds that will elapse between this and the next operation in the script.Next, <opcode char> is a single case-sensitive (!!) letter that identifies which operation to be performed(see list below).

  • R: IMG_REGISTER
  • r: IMG_ROT90CLKW
  • b: IMG_BLUR
  • s: IMG_SHARPEN
  • v: IMG_VERTEDGES
  • h: IMG_HORIZEDGES
  • T: IMG_RETRIEVEThe <overwrite> field should always be set to 1 (for simplicity we do not handle cases with overwrite = 0).Finally, the <image ID> should be the ID on which the operation should be performed. This field has aspecial meaning in the case of IMG_REGISTER operations. Only in this case, it tells the client which one ofthe files scanned in the images folder should be registered with the server. In all the other cases, an ID = n tells the client to request the operation on the n th image that it has registered with the server.When a script is requested at the client, the client will conveniently report how it has understood the script.For instance, when using the script:

4CS-350 - Fundamentals of Computing Systems::Homework Assignment #8 - BUILD Problem 2Submission Instructions: in order to submit the code produced as part of the solution for this homeworkassignment, please follow the instructions below.You should submit your solution in the form of C source code. To submit your code, place all the .cand .h files inside a compressed folder named hw8.zip. Make sure they compile and run correctly according to the provided instructions. The first round of grading will be done by running your code.Use CodeBuddy to submit the entire hw8.zip archive at https://cs-people.bu.edu/rmancuso/courses/cs350-fa24/codebuddy.php?hw=hw8. You can submit your homework multiple times until the deadline.Only your most recently updated version will be graded. You will be given instructions on Piazza on howto interpret the feedback on the correctness of your code beforethe deadline.5

标签:operations,Computing,Fundamentals,image,should,client,semaphore,CS,server
From: https://www.cnblogs.com/BUS001/p/18593526

相关文章

  • 「CSP-2024 游记」翠竹泣墨痕,锦书画不成。
    翠竹泣墨痕,锦书画不成。情针意线绣不尽,鸳鸯枕。$\\\\\\\\$——《蜀绣》初赛Day0因为学校晚自习不让请假的缘故只得回家狂做隔壁NFLS训练的初赛模拟题。立了个不过初赛就AFO的Flag。不过每次模拟倒是一直上不了九十。虽然模拟赛最后还是没有补完Day1大......
  • 「CSP-2024 游记」翠竹泣墨痕,锦书画不成。
    翠竹泣墨痕,锦书画不成。情针意线绣不尽,鸳鸯枕。$\\\\\\\\$——《蜀绣》初赛Day0因为学校晚自习不让请假的缘故只得回家狂做隔壁NFLS训练的初赛模拟题。立了个不过初赛就AFO的Flag。不过每次模拟倒是一直上不了九十。虽然模拟赛最后还是没有补完Day1大......
  • css variable的使用方法和好处有哪些?
    CSS变量(也称为CSS自定义属性)使用--开头,例如--main-color:#007bff;。它们可以在文档的根、任何元素或特定选择器中声明。使用方法和好处如下:使用方法:声明变量:在选择器中使用--前缀声明变量。例如::root{--main-color:#007bff;--font-size:16px;}.cont......
  • 有使用过css的images-set吗?它能解决什么问题?
    是的,我了解CSS的image-set()。它主要用于解决响应式图片和高分辨率屏幕适配的问题。image-set()允许你在CSS中指定多个图像,浏览器会根据设备的特性(例如像素密度和分辨率)选择最合适的图像显示。这比手动使用<picture>元素或mediaqueries更简洁高效。它能解决以下问题:......
  • css子元素会继承父元素的font-size吗?请解释下面父子元素各字体的大小[代码]
    是的,CSS子元素会继承父元素的font-size属性,除非子元素自身显式地设置了font-size值。你没有提供具体的代码示例,所以我用一个例子来说明:<!DOCTYPEhtml><html><head><style>body{font-size:20px;/*父元素body设置字体大小为20px*/}div{/*div继承了b......
  • 使用css如何拉伸字体?
    CSS提供了几种方法来拉伸字体,但需要注意的是,过度拉伸会降低文本的可读性。以下是一些常用的方法以及它们的优缺点:1.font-stretch属性:这是专门用于拉伸字体的属性,它会根据字体的可用样式进行拉伸。并非所有字体都支持所有拉伸值。font-stretch:ultra-condensed|extra-con......
  • 使用css3画个旋转的立方体
    <!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>RotatingCube</title><style>body{background-color:#333;display:flex;justify-content:center;align-items:center;min-height:......
  • 如果要你自己设计一个css框架,说说你的思路
    如果我要设计一个CSS框架,我的思路会围绕以下几个核心原则:1.模块化和可扩展性:原子化CSS(AtomicCSS)或实用优先(Utility-First)的方法:我会倾向于采用这种方法,因为它提供了最大的灵活性,并减少了对特定组件类的依赖。可以根据需要组合小型、单一用途的类,从而构建复杂的......
  • java 发送邮件 css-style 样式丢失错乱问题,有解决方案
    邮件系列java如何实现发送邮件email?java搭建属于自己的邮件服务器java发送邮件css-style样式丢失错乱问题,有解决方案java发送邮件-04-java邮件发送http接口如何定义?开源项目email:一行代码实现邮件发送前言大家好,我是老马。大家日常开发,对于邮件发送应该能不......
  • 65. Web前端网页案例——【海贼王动漫主题网页(10页)】 大学生期末大作业 html+css
    目录 一、网页概述二、网页文件三、网页效果四、代码展示1.html2.CSS五、总结1.简洁实用2.使用方便3.整体性好4.形象突出5.交互式强六、更多推荐♬♬♬欢迎光临我的CSDN!这里是Web前端网页案例大集汇,有各行各业的前端网页案例,每天会持续更新!如果你对Web前端网......