In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to achieve Perl multithreading, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Perl multithreading of Perl language
There are generally two ways to implement Perl multithreading, while the old version is actually a multi-process approach.
1. Thread- > New
This method is the traditional old method, it is very similar to folk, when you create a new process, all the variables in the current memory space will be copied and passed to the new process. Shared data has been implemented. With the development of technology, this paper does not do in-depth research on this method.
II. IThread
This is done by creating a new perlinterpreter. By default, all data and variables are not shared by threads. If you want to share a variable, you need to do it through threads::shared. When using this method, you should pay attention to the following three points:
◆ variables are not shared in threads by default.
◆ references namespaces through "usethreads", not through eval,do or require.
◆ must refer to "threads::shared" if it has variables to share. And when defining variables, it is as follows:
My$var1:shared= "value"
The following is a simple example of using Perl multithreading.
In many cases, using Perl multithreading can achieve very good results, and can save a lot of time to complete very complex work. However, from the description file of the perlthreads module, we can see that it also has many shortcomings. For example, when using Perl multithreading, it is necessary to ensure that all referenced modules support thread. In practical application, it is very difficult for us to do so. For example, we want to Perl multithreading, but at the same time we need to use the OLE module to operate activex. This use case should be a very common use case. Does that mean we have to give up using Perl multithreading at this time? No, this article introduces an example that can use Perl multithreading and ole.
The solution for this situation on the official http://www.cpan.org/ website is:
Ifthemodulewillonlybeusedinsideathread, youcantryloadingthemodulefrominsidethethreadentrypointfunctionusingrequire (andimportifneeded): subthr_func {requireUnsafe::Module#Unsafe::Module- > import (...);.} Ifthemoduleisneededinsidethemainthread, trymodifyingyourapplicationsothatthemoduleisloaded (againusingrequireand- > import ()) afteranythreadsarestarted, andinsuchawaythatnootherthreadsarestartedafterwards.
Thirdly, we mainly discuss the second case, that is, the non-thread module is referenced in the method.
Thank you for reading this article carefully. I hope the article "how to implement Perl multithreading" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.