unexpected forced logout on iMac
The loginwindow process is responsible for logging you in and out - so if you don't get a chance to save your work, then that one process has crashed.

Look for crash logs in the console app to confirm this. While you are there, perhaps look over the console and system.log files in the console application. You will have to take note of the times when the crashes happen and dig into the messages a bit.

They are noisy, and some errors are not - some harmless messages are very important. It's best to compare a good log out with a bad log out to see what changed (and get a feeling what messages are normal)

You could also punt and take it to someone that knows how to diagnose software issues, but it's clear that the login window process has quit and the mac is forced to kill all the other user level processes to attempt to stay running. This is by design and intended to get you to have it looked at since it is a serious software problem.