In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about the usefulness of C # WiteOne. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
C # provides two thread-related classes, Mutex and Interlocked, both under the Threading namespace! Two instance methods of WiteOne,ReleaseMutex are provided in Mutex: the function of C # WiteOne is to "block the current thread and provide atomic operations on that thread", that is, when a thread encounters a C # WiteOne, if there is no thread operating in the WiteOne, then the thread goes in to operate and there are threads in it. All threads that arrive here need to queue up for the thread inside to finish executing, and the end tag to control this operation is to use the ReleaseMutex method!
Just like C # WiteOne is a lock ~ and ReleaseMutex is a key when all 10 people see the door, the person who arrives at the door will see that there is no one in the house, so he will go in and lock the door at the same time. The person behind him will naturally wait at the door, and when he has finished his duty in the house, he will use the key to open the door! After going out, give the lock to the second comrade in line at the door, and the second comrade will do the same again. If the comrade does not hand over the right of use to the second person after performing the task, then the room will naturally be empty if the door is still locked. There is no need to worry that the door will open automatically, as long as the previous person is no longer in the room.
Then let's talk about this Interlocked. It is officially stated that the concept of "incrementing or decreasing a variable and then saving it" is that only one thread is operating on this variable. Other threads are not allowed to interfere with the operation. When you perform an atomic operation on a variable, the variable is locked and other threads cannot access it. I can only hang and wait for this variable to be unlocked. I think what I actually use is what Mutex does.
Public class MutexTest {private static int poolFlag = 0; / / marked private const int amountThread = 10; / / Total number of threads private const int maxThread = 3; / / number of executable threads private static Mutex muxConsole = new Mutex (); public static void Main () {for (int I = 0; I)
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.