Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6826837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:11:42+00:00 2026-05-26T22:11:42+00:00

I have a program which uses POSIX timer ( timer_create() ). Essentially the program

  • 0

I have a program which uses POSIX timer (timer_create()). Essentially the program sets a timer and starts performing some lengthy (potentially infinite) computation. When the timer expires and a signal handler is called, the handler prints the best result yet that has been computed and quits the program.

I consider doing the computation in parallel using OpenMP, because it should speed it up.

In pthreads, there are special functions for example for setting signal masks for my threads or so. Does OpenMP provide such control, or do I have to accept the fact that the signal can be delivered to any of the threads OpenMP creates?

Also, in case I am currently in a parallel section of my code and my handler is called, can it still safely kill the application (exit(0);) and do things like locking OpenMP locks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:11:42+00:00Added an answer on May 26, 2026 at 10:11 pm

    OpenMP 3.1 standard says nothing about signals.

    As I know, every popular OpenMP implementation on Linux/UNIX is based on pthreads, so OpenMP thread is pthread’s thread. And generic rules of pthreads and signals apply.

    Does OpenMP provide such control

    No any specific control; but you can try to use pthread’s control. Only problem is to know how much OpenMP threads are used and where to place controlling statement.

    the signal can be delivered to any of the threads OpenMP creates?

    By default, yes, it will be delivered to any thread.

    my handler is called,

    Usual rules about signal handler still applies. Functions allowed in signal handler are listed at http://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html (at the end of page)

    And printf is not allowed (write is). You can use printf if you know that at the moment of signal printf is not used by any thread (e.g. you has no printf in parallel region).

    can it still safely kill the application (exit(0);)

    Yes it can: abort() and _exit() are allowed from handler.

    Linux/Unix will terminate all threads when any thread does exit or abort.

    and do things like locking OpenMP locks?

    You should not, but if you know that this lock will be not locked at the time of signal handler run, you can try to do this.

    !! UPDATE

    There is an example of adopting signalling to OpenMP http://www.cs.colostate.edu/~cs675/OpenMPvsThreads.pdf ("OpenMP versus Threading in C/C++"). In short: set a flag in handler and add checks of this flag in every thread at every Nth loop iteration.

    Adapting a signal based exception mechanism to a parallel region

    Something that occurs more with C/C++
    applications that with Fortran applications is that
    the program uses a sophisticated user interface.
    Genehunter is a simple example where the user
    may interrupt the computation of one family tree
    by pressing control-C so that it can go on to the
    next family tree in a clinical database about the
    disease. The premature termination is handled in
    the serial version by a C++ like exception
    mechanism involving a signal handler, setjump,
    and longjump.OpenMP does not permit unstructured control
    flow to cross a parallel construct boundary. We
    modified the exception handling in the OpenMP
    version by changing the interrupt handler into a
    polling mechanism. The thread that catches the
    control-C signal sets a shared flag. All threads
    check the flag at the beginning of the loop by
    calling the routine has_hit_interrupt( )
    and skip the iteration if it is set. When the loop
    ends, the master checks the flag and can easily
    execute the longjump to complete the
    exceptional exit (See Figure 1.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program which uses an io_service and several threads. It instantiates some
I have written a small program which uses function pointers to do some numerical
I have a program, which uses quickreports 5 to generate some reports. The program
I have a C program which uses Lua for scripting. In order to keep
I have avery simple program which uses MediaPLayer. I am new to java and
Below, I have a simple program which uses the CImg library (http://cimg.sourceforge.net/) which iterates
I have been trying to create a simple program with Python which uses OpenCV
Say, if I have a Lisp program, which uses (eval 'sym) and looks it
I have a small Python program, which uses a Google Maps API secret key.
I have a program which has some Textareas / Labels these can be anywhere

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.