In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what the concept of Perl threading is, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Overview of Perl threads
Perl thread is a single execution flow, which is the smallest control unit in the execution of all programs, that is, the smallest task unit that can be scheduled by CPU. There is both a connection and a completely different relationship between Perl threads and processes. To put it simply, a Perl thread must belong to a process, and a process contains at least one or more Perl threads. Early computer systems could only run one program at a time, so when there were multiple programs to be executed, the solution was to queue them up and execute them sequentially. The emergence of processes breaks this pattern, and CPU resources are divided according to time slices and allocated to different processes.
In this way, although the execution of the process is still serial from a micro point of view, from a macro point of view, different programs are already executing in parallel. If we apply the same idea to a process, it is natural to subdivide the process into smaller units of execution, the Perl thread. Because a process often needs to perform multiple similar tasks at the same time, these subdivided Perl threads can share the same resources such as code segments, data segments and file handles. With the process, we can run multiple programs such as Firefox and MicrosoftOfficeWord on a single CPU computer system at the same time; with Perl threads, we can make Firefox load multiple different pages in different tags at the same time, and check syntax errors while editing documents in OfficeWord. Therefore, Perl threads bring us higher CPU utilization, faster program response, more economical use of resources and better adaptability to multi-CPU architecture.
History of Perl threads
5005threadsPerl thread model
Perl's support for Perl threads dates back to the release of Perlv5.005 in July 1998. Its statement points out that Perlv5.005 has added support for operating system-level Perl threads, and this new feature is an experimental product, which is what we now call the 5005 thread Perl thread model. For the 5005 threadsPerl threading model, by default, all data structures are shared, so users must be responsible for synchronous access to these shared data structures. Today, 5005threads is no longer recommended for use, and the 5005threadsPerl threading model will no longer be supported in future versions of Perlv5.10.
IthreadsPerl thread model
A new Perl threading model, interpreterthreads, or ithreads, was introduced in Perlv5.6.0 released in May 2000, and it was in this release statement that the 5005threadsPerl threading model may be disabled in the future. However, ithreads was a new experimental Perl threading model at that time, and users could not use it directly. The way to do this was to simulate it through the fork function. After two years of development, Perlv5.8.0 was officially released in July 2002, when ithreads was a relatively mature Perl threading model. The statement also encouraged users to switch from the old 5005threadsPerl threading model to the new 5005threadsPerl threading model, and made it clear that the Perl threading model would eventually be eliminated. Everything discussed later in this article is also based on the new ithreadsPerl threading model. The most distinctive feature of the ithreadsPerl threading model is that none of the data structures are shared by default, which we will see more deeply later.
Which Perl threading model is supported in the existing environment
Since there may be two different Perl threading models in Perl, it's natural to determine which Perl threading implementation is supported by the existing Perl environment. To sum up, we have two ways:
In shell, we can get information about the current Perl thread model by executing the perl-V | grepusethreads command, such as
Query Perl current Perl thread model in listing 1.shell
> perl-V | grepuse.*threads config_args='-des-Doptimize=-O2-g-pipe-m32-march=i386-mtune=pentium4-Dversion=5.8.5-Dmyhostname=localhost-Dperladmin=root@localhost-Dcc=gcc-Dcf_by=RedHat Inc.-Dinstallprefix=/usr-Dprefix=/usr-Darchname=i386-linux-Dvendorprefix=/usr-Dsiteprefix=/usr-Duseshrplib-Dusethreads-Duseithreads-Duselargefiles-Dd_dosuid-Dd_semctl_semun-Di_db-Ui_ndbm-Di_gdbm-Di_shadow-Di_syslog-Dman3ext=3pm-Duseperlio-Dinstallusrbinperl-Ubincompat5005-Uversiononly-Dpager=/usr/bin/less-isr-Dinc_version_list=5.8.45.8.35.8.25.8.15.8.0' usethreads=defineuse5005threads=undefuseithreads=defineusemultiplicity=define
It is not difficult to see from the results that support for the ithreadsPerl threading model is provided in the current Perl environment.
In Perl programs, we can also use the Config module to dynamically obtain information about the Perl thread model, such as
Dynamically get the current PerlPerl thread model in the listing 2.Perl program
#! / usr/bin/perl # useConfig; if ($Config {useithreads}) {printf ("Helloithreads\ n")} elsif ($Config {use5005threads}) {printf ("Hello5005threads\ n");} else {printf ("Cannotsupportthreadinyourperlenvironment\ n"); exit (1);}
It is worth mentioning that Perl can only support one of the 5005threads and ithreadsPerl thread models at the same time. You can't use both Perl threading models in a Perl environment. Everything discussed later in this article is based on the ithreadsPerl threading model.
These are all the contents of the article "what is the concept of Perl threading?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.