Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow graceful exit on ^C #12

Open
programagor opened this issue Sep 21, 2018 · 1 comment
Open

Allow graceful exit on ^C #12

programagor opened this issue Sep 21, 2018 · 1 comment
Labels

Comments

@programagor
Copy link
Owner

Right now, the program can be interrupted while a thread is writing its buffer into the output memory/file. This results in a band visible in the output image.

Let's implement SIGTERM handling, which interrupts the worker threads only at specified points (i.e. not while writing to a file)

@programagor
Copy link
Owner Author

programagor commented Sep 24, 2018

Cleanup function for thread cancellation needs to be implemented. This function is registered via void pthread_cleanup_push(void (*routine)(void *), void *arg);, and optionally can be executed via void pthread_cleanup_pop(1);
http://man7.org/linux/man-pages/man3/pthread_cleanup_push.3.html

During sensitive operation, the cancellability state needs to be disabled via pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL), and otherwise enabled via pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL). The cancellability type can be asynchronous, because we only care about the consistency of the output arrays and counters, which are modified when the cancel state is disabled. However, everyone keeps advising against that, so let's use deferred instead. This is done via pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);.
http://man7.org/linux/man-pages/man3/pthread_setcancelstate.3.html

Cancellation points are created via pthread_testcancel();
http://man7.org/linux/man-pages/man3/pthread_testcancel.3.html

Cancel is issued via int pthread_cancel(pthread_t thread);, can this be called from a signal handler?

programagor added a commit that referenced this issue Sep 25, 2018
This is to start addressing #12
programagor added a commit that referenced this issue Sep 25, 2018
This continues addressing #12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant