6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 32. 2.8 Serializing access to shared state So we see that if we are to allow for concurrent processes to take place, we need some way of specifying units of computation that entily, but there wll be need to take place as a whole, before any other computation can execution of a procedure in each serialized set is start ermitted to happen at a time, dure in the set is being executed, then a Serialization implements the following idea: Processes will that attempts to execute any procedure in the execute concurrently, but there will be certain collections of procedures that cannot be executed concurrently. More precisely, se serialization to control access to shared variables. serialization creates distinguished sets of procedures such that only one execution of a procedure in each serialized set is permitted to happen at a time. If some procedure in the set is being executed 4 I then a process that attempts to execute any procedure in the set will be forced to wait until the first execution has finished We can use serialization to control access to shared variables. For example, if we want to update a shared variable based on the previous value of that variable, we put the access to the previous value of the variable and the assignment of the new value to the variable in the same procedure. We then ensure that no other procedure that assigns to the variable can run concurrently with this procedure by serializing all of these procedures with the same serializer. This guarantees that the value of the variable cannot be changed between an access and the corresponding Slide 32.2.9 We can constrain the concurrency by using serialized procedures.Serializers to"mark"critical regions These are created by serializers, which are constructed by make We can mark regions of code that cannot overlap execution serializer, whose implementation we will get to shortly. A n time. This adds an add aint to the partial serializer takes a procedure as argument and returns a serialized ordering imposed by the separate processes. procedure that behaves like the original procedure. All calls to a a serialized procedure that behaves like the original given serializer return serialized procedures in the same set. This ed set is underway, this procedure must wait for tha means that a procedure may not begin execution if another ss completion before beginning procedure from the same set has not yet completed execution Slide 32.2.10 Serialized execution Thus, in contrast to the example in a previous slide, executing the code shown here can produce only two possible values for x, 101 or 121. The other possibilities are eliminated because the 1x(+x1)))) execution of pl and p2 cannot be interleaved (parallel-execute p5 p6) Pl: a: lookup first x in p3 b: lookup seoond x in c: assign product or a and b to x 2:d:iook甲xip4 Deac 11111111216.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 32.2.8 So we see that if we are to allow for concurrent processes to take place, we need some way of specifying units of computation that need to take place as a whole, before any other computation can start. Serialization implements the following idea: Processes will execute concurrently, but there will be certain collections of procedures that cannot be executed concurrently. More precisely, serialization creates distinguished sets of procedures such that only one execution of a procedure in each serialized set is permitted to happen at a time. If some procedure in the set is being executed, then a process that attempts to execute any procedure in the set will be forced to wait until the first execution has finished. We can use serialization to control access to shared variables. For example, if we want to update a shared variable based on the previous value of that variable, we put the access to the previous value of the variable and the assignment of the new value to the variable in the same procedure. We then ensure that no other procedure that assigns to the variable can run concurrently with this procedure by serializing all of these procedures with the same serializer. This guarantees that the value of the variable cannot be changed between an access and the corresponding assignment. Slide 32.2.9 We can constrain the concurrency by using serialized procedures. These are created by serializers, which are constructed by makeserializer, whose implementation we will get to shortly. A serializer takes a procedure as argument and returns a serialized procedure that behaves like the original procedure. All calls to a given serializer return serialized procedures in the same set. This means that a procedure may not begin execution if another procedure from the same set has not yet completed execution. Slide 32.2.10 Thus, in contrast to the example in a previous slide, executing the code shown here can produce only two possible values for x, 101 or 121. The other possibilities are eliminated, because the execution of P1 and P2 cannot be interleaved