D'Alembert's principle and the work done by constraint forces in Atwood's machine From what I understand, constraint forces do no work because they are perpendicular to the allowed virtual displacements of the system. However, if you consider an unbalanced Atwood machine, in which both masses are accelerating in opposite directions, you'll find that the tension force of the wire (a constraint force), which pulls the lighter mass up, is parallel to the displacement, which means it does work (right?).
Now, I understand that the same is true for the other side: the tension force on the heavier mass is parallel to the displacement, but in the opposite direction, so that if you add the work done by the tension force on the heavier side to the work done by the tension force on the lighter side you get zero.
So my question is: would it be correct for me to say that individual constraint forces can do work, but it's the sum of the work done by all the constraint forces which is always equal to zero? If this is true, it's a bit different from the notion I had before, which was that individual constraint forces never do work because they are always perpendicular to the displacement.
 A: The author of the excellent book where I found this problem (The Lazy Universe) explains in another part of the book:

A surprisingly tricky example is the case of a sliding block which is
  pushed across a table-top by a force, say, pushed by your finger (we
  ignore friction). The displacement of the block is anywhere on the
  surface whereas the reaction-force acts at right-angles to this
  surface preventing the block from burrowing down into the table. So
  far, this makes sense. But, hang on, there is also a reaction against
  your finger, from the block, and this reaction is in line with the
  block’s displacement. The trick is to appreciate that the block’s
  displacement due to the finger-push is an actual, not a virtual,
  displacement. We can hypothetically freeze the block (switch to a
  different reference frame) and get rid of the distraction of its
  actual motion. Then we realize that the finger can’t depress the block
  as if it were so much sponge-cake, as there is a reaction-force of the
  block against the finger. However, the finger is still allowed, infinitesimally, virtually, to move within the back
  face of the block, at right-angles to this reaction-force. This is a
  general result: for any virtual displacement, being ‘harmonious’ is
  the same thing as being in a direction perpendicular to the reaction
  forces.

I feel this is the answer to my question, but I can't say I understand how this translates to the Atwood machine problem. This is my guess:
The important thing is not to confuse virtual displacements with actual displacements. Sometimes, the actual physical displacements cannot be chosen as virtual displacements. Virtual displacements occur without the passage of time. If we think of the example above, while time is frozen the finger cannot actually move in the direction the block moves when time is flowing. For it do so, it would have to compress the block, but the block is inelastic. So that's not an allowed virtual displacement. But with things frozen in time, the finger is allowed to move within the face of the block (like up and down across the face), and this motion is at right-angles to the reaction (constraint) force from the block on the finger.
As @alephzero stated in another answer, the real constraint in the Atwood machine "is that the string has constant length". This means that, like the block in the previous example, the string can't be compressed. Therefore, if we freeze time, we'll find that we can't take the virtual displacement of the blocks to be the same as the actual displacement, i.e, "up and down", i.e, in the direction of the strings. For them to do so with time frozen they would have to compress the strings, and the strings can't be compressed. So we are once again "getting distracted by the actual motions". This is another case where we can't take the actual displacements as the virtual displacements. The virtual displacements allowed for the blocks are actually at right angles to the string, not up and down, but sideways!
Am I onto something?
A: What is the constraint enforce by the tension? How does it show up in your generalized coordinates?
As I noted in the comments it is usual to chose a set of generalized coordiantes with a single position for each rope (and the location of the other end found by calulating from there); this form has the constraints built-in, so that there is no way to express a violation of the constraint in the coordiante space.1
But you don't have to do that. You can give each end of a rope in the problem it's own position, and then the constraints imposed by the tensile force take the form
$$ x_i + x_j = L_{ij} \;,$$
which identifies an allowed surface in the (enlarged) coordinate space. In this form tension acts to keep the system on the the allowed surfaces (that is perpendicular to virtual displacement that lead to position violating the constraints).

1 The ability to do this is, of course, one of the great strengths of variational mechanics. But you should be aware of what you are doing because you often have to undo it if you want to obtain more information about the system. For instance, to get information on the mgnitude of contraint forces, you have to re-choose coordaintes allow you to expressed violations of the constraints and then re-impose the constraints explcitly.
A: Whether the tension is a constraint, or not, depends how you model the problem.
Method 1: consider "the two masses plus the rope" as one body, and use just one coordinate to measure its position. Obviously the "single body" changes shape as it moves, and one mass moves up and the other moves down, but that doesn't affect the general principle of calculating its strain and potential energies in Lagrangian mechanics.
In this case, the tension is simply an internal force in the body and never appears in any equations of motion.
There is a constraint force between the rope and the pulley, but that force is normal to the pulley and therefore does no work and can be ignored.
Method 2: consider the two masses as separate bodies, acted on by the tension in the string. Because the strings is massless and the pulley is frictionless, the tension at each end is equal. In this case, you do have a constraint, which is that the string has constant length, therefore the displacements (and velocities and accelerations) of the two masses are equal and opposite.
That constraint on the way the system can move means that the work done by the forces at each end of the string sum to zero.
A: D'Alembert principle is nothing but a prescription of a type of constraints -- also known as ideal constraints -- such that the equation of motion can be written in the form of  Euler-Lagrange equations, by using an arbitrary system of coordinates obtained by "solving the constraint equations".
The definition requires that, at fixed time, the total (infinitesimal) work of all reactive forces for any displacement of the system compatible with the constraints  vanishes. (It would be better to speak about total power instead of total work.)
This is a formal work because the displacements are not those of the actual motion of the system: they are defined at fixed time and join two different configurations compatible with the constraints at that time. In fact, it is called virtual work and also the said  (infinitesimal) displacements are said virtual displacements for the same reason.
However, if the constraint equations do not explicitly depend on time, the aforementioned work coincide with the actual work. In this case, D'Alembert principle is equivalent to the requirement that the total work of reactive forces vanishes.
This is the case, for instance, when considering the internal forces of a rigid body. 
As a special case is that of a system of reactive forces due to smooth constraints. In that case the single works vanish separately. But this is a quite peculiar situation.
As a matter of fact, once the problem of motion is reformulated in the free coordinates (adapted to constraints), if the reactive forces satisfy D'Alembert's principle the reactive forces disappear from the formalism in the Euler-Lagrange equations. 
A: Gravity is pulling the weights down, the cable provides a directly opposing restraint, to keep the weights from accelerating downwards at 9.8 meters per second per second. The actual work is done by using the heavier weight's gravitational potential. 
