 All right, so it's the last screencast for assignment one and in this one We're going to just look a little bit one of the synchronization problems So assignment one, you know just divides into two parts in the first part you implement locks condition variables Read a writer locks and write a test for reader writer locks And the second part you implement use those primitives to solve two synchronization problems There's this whale mating problem and a stoplight problem What important caveat here is that it is really important to get your synchronization primitives working Not only before you start the synchronization problems because you will struggle to solve the problems If you don't have working primitives, but also because the primitives get used throughout the rest of these assignments So if your locks don't work, you will struggle mightily with assignment two and assignment three And it is likely that you will not be able to complete those assignments without working locks and condition variables Reader writer locks may be useful for those assignments You will find places where they are potentially appropriate But the most important part of this assignment is to complete your locks or condition variables correctly So that you can use them down the road The nice thing about this however is that it's very easy to check whether or not those are correct So once you've completed those, you know If you have course nap to talk to just show them those primitives and they should be able to verify very quickly That they're correct because there's just not a huge amount of code to write for locks and condition variables Reader writer locks You also can get help with but again They're just not as critical down the line and the synchronization problems are by far the least important part of the assignment Because this is code that won't even be included in your kernel in later assignments You'll disable the sync probes option in the kernel configuration and you won't even have that code there That said hopefully these are fun give you a chance to think a little bit about synchronization So let's see how they work because like The reader writer lock tests We haven't really given you useful testing code here. The testing code will do something It'll start off threads that print things, but you kind of need to be able to process the output So where does this code? Let's start off. Where does the code live? It lives in sync probes. So we've divided the The code that you're going to write here into two sections There's stuff that's in sync probes and let's look at the way I made an example and Then there's test code for that in test sync probes. See now. Remember we will overwrite all the contents of This file along with everything in testing and select other files when we do our automated gradient So please you are welcome to modify the file. This this comment is a little bit alarmist But it will be overwritten. So we'll change the comment to make that a little bit more clear But everything in here is going to be removed. So Now in order to remember the whale may name problem as described in the assignment which I'll pull up here Right, so we have the whale mating problem and the idea here is that we are going to You have three types of thread you have males females and matchmakers and The males and females want to make with each other, but they need a matchmaker to help them So we're going to start our driver code over here is going to if you look at the whale mating example here it starts Goes to these three types of Thread and mating I remember correctly is Where I'm a and mating is 10 so we're going to start 10 male threads 10 male female threads and 10 matchmakers and Then each one of those threads when it starts is going to start its own Rapper it's going to start in its own wrapper function. So we have a male wrapper and the male wrapper Really just calls male, which is the function that you need to write Your function should call male start and male end male start when the male starts mating and they'll end when it finishes and Same thing that the code for the females and for the matchmakers is identical So the code that you need to write over is over here it's just really three functions male female and matchmaker and Want to think about what's the invariant here that we would be able to test in this assignment? So for example, what should happen if we start up 10? Let's say we start 10 female threads. What should happen? Then let's say we start 10 male threads. What should happen at that point now? Let's say we start one matchmaker now. What should we see happen? Remember the males and females you need a trio of threads to all have been started and ready To for there to be a match So if I started 10 females and then 10 matchmakers Still nothing is going to happen. And so this is really that the good way to think about the problem Clearly you need some type of communication between the males the females and the matchmakers this problem is You know because it requires this inter thread communication Not a good fit for walks, which don't support that very naturally However, it is a potentially a good fit for several of the other synchronization Primitives that are designed to support communication between multiple threads The code that we've given you when you call matchmaker starting matchmaker and we'll just print out the Whales type and ID so this will print out you know male and Maybe, you know, you know print off. Let's see here. I think when we set the name of the thread Yeah, so we we set the names of the thread down here to male thread You know male whale thread one female whale thread one. So is this prints out? You know that out you'll have to look at that output very carefully to make sure that things are happening correctly However, we would encourage you to write a better test case here that actually You know explore some of the corner cases. I just discussed or Processed the output in a more intuitive way by looking at the output You can verify that your solution is correct but your eyes may start to hurt after a while and it's certainly a case where you can write code in this file that Ensures that your code is correct and we know this because we're going to do it So this is an example of how to approach one of the synchronization Problems the test code that you write for this will also It'd be helpful for you to look at some of the other tests that we've written and to think about the test That you wrote for your reader writer locks That's all good luck on assignment one this is the last screencast and Hope you may you write working synchronization produce