Multi-threaded routines run for a long time efficiency drop analysis

Source: Internet
Author: User

Recently in writing a search engine, there is an intermediate program is to analyze the word segmentation results file, set up an inverted index. Originally written is single-threaded, inefficient to no language, and then changed to multi-threaded. I thought everything was going to be all right, but when I analyzed nearly 2000 files, there was no difference between inefficient and single-threaded. Open Task Manager, the number of threads display 3 (I set the number of child threads up to 15, plus the start, the program just run the number of threads can reach 20).

Baidu, Windows, a single program of the number of threads is capped, generally only open to about 2000. And in my program for convenience, each sub-thread is set to detach state. In this state, when the thread ends, other threads are not able to reclaim their resources and must be available when the program exits. In other words, when the program has processed nearly 2000 files, the system resources have been exhausted, so efficiency has been reduced.

Knowing this, the problem is solved, the line Cheng to joinable (can be combined) state, in one thread waiting for each sub-thread to end.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Multi-threaded routines run for a long time efficiency drop analysis

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.