How does one keep a session alive across two different URLs? I have the same drupal 7 installation running on www.mysite1.com and www.mysite2.com.

Most people redirect mysite.com to www.mysite.com, but doing so users logged in on a site aren't kept logged-in in the other site.

Since mysite1.com is running the same code as mysite2.com, I want the users to remain logged-in when switching from a site to the other one.

I assume Drupal stores the user's session ID, and when switching to the other site, the users get a new session ID, but surely there must be a way to make the two sites aware of each other, so that users are kept logged-in across two sites.
You can use Bakery Single Sign-On System module.
https://www.drupal.org/project/bakery