How can I detect when a user have closed a window created with GLUT? Otherwise GLUT will keep working in the background. Is there any multiplatform solution?

Thanks in advance!