Question: I've just been messing around with threads in Java to get my head around them (it seems like the best way to do so) and now understand what's going on with synchronize, wait() and notify().

I'm curious about whether there's a way to wait() on two resources at once. I think the following won't quite do what I'm thinking of (**edit**: *note that the usual while loops have been left out of this example to focus just on freeing up two resources*):

```
synchronized(token1) {
    synchronized(token2) {
        token1.wait();
        token2.wait(); //won't run until token1 is returned
        System.out.println("I got both tokens back");
    }
}

```

In this (very contrived) case token2 will be held until token1 is returned, then token1 will be held until token2 is returned. The goal is to release both token1 and token2, then resume when both are available (note that moving the token1.wait() outside the inner synchronized loop is not what I'm getting at).

A loop checking whether both are available might be more appropriate to achieve this behaviour (would this be getting near the idea of double-check locking?), but would use up extra resources - I'm not after a definitive solution since this is just to satisfy my curiosity.

**Edit** Let's just for the sake of argument say that the two tokens here represent two distinct resources that the thread must use at the same time, and that some other threads will need both at the same time.

Answer: 
"\r" should work for both windows and Mac OS X.

Something like:

```
std::cout << "will not see this\rwill see this" << std::flush;
std::cout << std::endl; // all done

```
I don't have access to a mac, but from a pure console standpoint, this is going to be largely dependent on how it treats the carriage return and line-feed characters. If you can literally send one or the other to the console, you want to send *just* a carriage return.

I'm pretty sure Mac treats both carriage returns and line-feeds differently than \*nix & windows.

If you're looking for in-place updates (e.g. overwrite the current line), I'd recommend looking at the `curses` lib. This should provide a platform independent means of doing what you're looking for. (because, even using standard C++, there is no platform independent means of what you're asking for).