How do long-haul pilots cope with boredom?
From what I know, airline transport pilots do not get large chunks of free time on a typical long-haul flight which you described. They may get small intervals of free time (e.g. 10-20 minutes), but for sure, not hours. They do need to constantly monitor if the airplane is flying on the correct course, on the assigned altitude, remaining fuel amounts and several other tasks, even when auto-pilot is engaged.

So what do pilots do when they are not flying at all?

Primarily, it depends on company policies. Delta does not allow pilots to do anything not related to flying the airplane:


  "You can't read a novel, but you could read a manual about procedures
  or about the airplane," ... "You can't read a newspaper. You can't use
  a laptop. That's strictly prohibited."


But generally speaking, pilots engage in causal chats between themselves and flight attendants (when they visit the cockpit)1.

When there are more than two pilots, one is generally allowed to get some rest. They can also browse through magazines or read some books or flight-related material, but mostly stay alert and available. Some will study for an upcoming proficiency or rating. One of the two pilots can go to the bathroom too. Getting locked out depends on pure luck.

So in a nutshell, there are several different activities/tasks pilots will engage into, each different for a particular flight.

This is a funny little anecdote I recently read, which fits this discussion very well:


  Murphy's law grants you a heap of emergencies once you start feeling
  bored in the cockpit.




1: As a ordinary passenger, I don't visit the cockpit, but I have noticed a few times what the flight attendants do. When they have free time, they have many things to talk about between themselves. Sometimes, they engage in small talk with passengers. They check their schedule and flights for the remainder of the day. Although the duties of flight attendants and pilots are entirely different, there are a bunch of activities which require their attention, and they can pass the time without getting too bored.