[AD] OSX - quit function

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


The main docs[1] say that attempting to quit an application by clicking the window's close button OR selecting the Quit menu OR pressing cmd+Q should call the function registered by set_close_button_callback() or do nothing if no function has been registered.

This is contradicted by the Allegro specifics[2], which state that Quit or cmd-Q closes the application. This is what happens in practice, by raising a SIGTERM.

This patch restores the 'general' documented behaviour.

Mac users _will_ complain if they can't cmd-Q an application. However, I'd rather alter the code than the documentation, because AFAICS there's no way to cleanly terminate an Allegro app (i.e. go via allegro_exit and any registered clean-up hooks.)

The reason for this is that there are 2 threads, one is the event loop and the other is the user code. A cmd-Q would call allegro_exit from the event thread. Concurrently, the second thread might call some allegro functions on a structure that has been or is being destroyed. The result is a crash or (worse) a hang.

I've found out that I cannot stop thread 2 from thread 1 - although there is a suitable function, pthread_cancel[3], asynchronous cancellation is not supported on OSX. Thread 2 is not guaranteed to hit a cancellation point, so deferred cancelation would not work either.

Therefore I would say to apply this patch and recommend that authors make use of set_close_button_callback().

Any comments?

Pete

[1] http://alleg.strangesoft.net/docs/en/set_close_button_callback.html
[2] http://www.talula.demon.co.uk/allegro/onlinedocs/en/alleg041.html
[3] http://www.hmug.org/man/3/pthread_cancel.php

Attachment: osx_closebutton.diff
Description: Binary data



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/