Let's assume that weights are placed on a massless piston and below the piston is a gas. If we remove all the weights at once, the work done by the gas should be the difference between the forces exerted by the gas and the atmosphere multiplied by the change in volume. However, we know that the pressure exerted by a gas is inversely proportional to its volume and hence the work done is given by the area under a curve. Is it okay to assume that the pressure of the gas instantaneously changes to atmospheric pressure when the weights are removed, as in Figure 4.10 of the link given?
http://web.mit.edu/16.unified/www/FALL/thermodynamics/notes/node34.html
http://web.mit.edu/16.unified/www/FALL/thermodynamics/notes/node34.html