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

  • Home
  • SEARCH
  • 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 4029100
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:18:09+00:00 2026-05-20T11:18:09+00:00

Is it possible to destroy the threads created by OpenMP? When the program starts,

  • 0

Is it possible to destroy the threads created by OpenMP? When the program starts, there is only the one thread. After the parallelized section multiple threads remain since there is a thread pool. Is there any way to destroy this pool after the parallel section is run?

I ask because I’m using OpenMP in a dynamic library, and the library handle cannot be closed while the threads are running (the program will segfault).

Thanks

More explanation:
I’m putting all parallelization code into modules (shared libraries). I then load the module and pass it a class derived from an abstract base class. The module then ‘runs’ that class in parallel. This way, I can use no parallelization, OpenMP, MPI, or anything else and can change the parallel scheme at run time or even on the fly. But OpenMP doesn’t destroy the threads, and when it comes time to manually dlclose the library, it will segfault since the resources are destroyed from underneath the thread (I believe). Letting the program finish without closing the library is probably ok for now, but wanting to manually close the library may still come up in the future (think changing scheme on the fly). Hope this makes sense 🙂 Thanks

  • 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-20T11:18:10+00:00Added an answer on May 20, 2026 at 11:18 am

    At this point in time, the OpenMP specification doesn’t give the user any ability to control when threads are destroyed. What you are saying is very interesting and hasn’t been brought up during any of the OpenMP language committee meetings to discuss the specification. Can you give more information about what you are doing and what the problem is? It would be helpful in bringing this discussion to the committee.

    Edit added 3/7 –

    Okay – here is a simple example that seems to work and it might get around your problem:

    $> cat prog.c  
    #include <stdio.h>
    #include <stdlib.h>
    #include <dlfcn.h>
    
    int main(void)
    {
      void (*f)(void);
      void *handle;
    
      handle = dlopen("./shared.so", RTLD_NOW);
      if (!handle) {
        printf("*** dlopen error - %s\n", dlerror());
        abort();
      }
    
      f = dlsym(handle, "foo");
      if (!f) {
        printf("*** dlsym error - %s\n", dlerror());
        abort();
      }
      f();
    
      if(dlclose(handle)) {
        printf("*** dlclose error - %s\n", dlerror());
        abort();
      }
      return 0;
    }
    
    $> cat shared.c 
    #include <omp.h> 
    #include <stdio.h>
    
    void foo(void)
    {
      int i;
    
      puts("... in foo\n");
    
      #pragma omp parallel for
      for (i=0; i<10; i++) 
        printf("t#: %i  i: %i\n", omp_get_thread_num(), i);
    
      puts("... exiting foo");
    }
    
    $> gcc -rdynamic -fopenmp prog.c -ldl -o prog                                                                   
    $> gcc -c -fopenmp -fPIC -o shared.o shared.c                                                                 
    $> ld -shared -o shared.so shared.o                                                                           
    $> ./prog
    ... in foo
    
    t#: 2  i: 4
    t#: 2  i: 5
    t#: 3  i: 6
    t#: 3  i: 7
    t#: 0  i: 0
    t#: 0  i: 1
    t#: 4  i: 8
    t#: 4  i: 9
    t#: 1  i: 2
    t#: 1  i: 3
    ... exiting foo
    

    While there is no OpenMP code in the main program (prog.c), I compiled it using the -fopenmp flag. This means that the OpenMP environment will be set up before the call to the shared library that is actually using OpenMP. This seems to get around the problem with doing a dlclose, since the environment is still there. It also allows the threads gotten by the first use of OpenMP to stay around for subsequent use. Does this work for getting around your problem (or does this only work for this simple example)?

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

Sidebar

Related Questions

Is it possible for me to create and destroy a TXMLDocument by myself in
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
I have an object that is called from two different threads and after it
Is it possible to kill a Java thread without raising an exception in it?
How to find out if object supports IHandle< T> and is there any possible
Possible Duplicate: (PHP) how to destroy or unset session when user close the browser
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: What Ruby IDE do you prefer? I've generally been doing stuff on

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.