The issue of releasing the thread resources created by the same thread multiple times occurs at the beginning of each thread. Use pthred_detach (pthread_self () to detach the thread resources.

Source: Internet
Author: User
Fxhnkf Question about the number of threads created

MyProgramCall pthread_create to create a thread. After the thread executes a certain task, pthread_exit (null );
The main program constantly creates this thread
Pthread_create returns 11 when it is found to be created more than 500th times. I checked errno. H, 11 is "no more processes"
Why ????

FxhnkfQuestion about the number of threads created

Thank you for your help!

Renstone921Question about the number of threads created

The number of processes created by the system is too large. You may use the process to simulate the thread in your system. Since the resources of your machine are not infinite, every time you create a thread, in most cases, it requires 1 MB of stack space. You can calculate how many threads can be created in your system.
The getrlimit function is used to obtain system resource restrictions. Let's take a look at your system restrictions. Or use the ulimit command.

FxhnkfQuestion about the number of threads created

But every time I call
Pthread_exit (null)
To release thread resources ??
Are these resources not released ?? My machine is HP's l2000
I don't think he's that bad.

Renstone921Question about the number of threads created

Sorry, I have never used an HP host. However, you should first determine the maximum number of processes in your system. This should be configurable.

FxhnkfQuestion about the number of threads created

Even if the maximum number of system processes can be configured, it can be changed more
If the actual pthread_exit (null); thread resources cannot be completely released, no matter how large the upper limit is, resources will always be used up to the upper limit.

I think there are other reasons

FxhnkfQuestion about the number of threads created

Thank you for participating in the discussion.

FxhnkfQuestion about the number of threads created

I hope you can have a look and talk more.

AlbcamusQuestion about the number of threads created

Are you sure that when the main thread calls pthread_create, all subthreads start with pthread_exit? (This is not necessary, but it may be caused by the failure of the sub-thread to exit)

Soul_of_moonQuestion about the number of threads created

[Quote] [I] the original post is published by "fxhnkf": [/I]
In my program, call pthread_create to create a thread. After this thread executes a certain task, pthread_exit (null );
The main program constantly creates this thread
Pthread_create returns 11 when it is found to be created more than 500th times. I checked errno. h and 11 is "no more proces... [/quote]
The cause of thread creation failure is:
Eagain not enough system resources to create a process for the new
Thread.

Eagain more than pthread_threads_max threads are already active.
It is estimated that your thread has not exited or has no time to release the resource. You can run the command PS-a-m | grep process name to check whether there are several threads in the process.

OpenxQuestion about the number of threads created

Need to call pthread_join?

AlbcamusQuestion about the number of threads created

Dizzy, not writing the thread for half a year, and I forgot to clean it.

The problem is solved as follows: at the beginning of each thread, you can use pthred_detach (pthread_self () to detach yourself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.