ArticleDirectory
- Old and young men fight back
Old and young men fight back
In the previous article, our maids can finally do things like others in the sun. The young masters can have afternoon tea with the maids sauce ~ Rare upper class society
This isAlways 1v1 private nvwaAndThe common maaid sauce when drinking teaThe most obvious difference ~
Under the bright midday sunshine, the white and long dining tables on both sides of the courtyard exchange recent anecdotes with handsome young masters, and enjoy the tea with a 1/3 chance as a waitress sauce, cute and stupid to serve, glittering look.
Meow ~~~~~~~~~~ : 3
But the distance is truly free ~~ It is still far away without lock. It is far away.
Because,
The old master and Young Master are still frequently transferred! Maaid sauce, you are still a great old man ~!
Let's take a look at what we call the chat room method:
Code snippet
-
- Channel Cr = session ["Chat"];
- Cr. Say (request ["Text"]);
-
-
- Foreach(VaRSInCr. Listen ())
-
- {
-
- Response. Write ("<P>");
-
- Response. Write (s );
- Response. Write ("</P>");
-
- }
-
-
This trip is terrible.
- Maids ~~ (Get instance)
- Tutorial ~! (Say & writelock)
- Tea ~! (Listen & readlock)
All the young masters and elders are here, Mr. Deacon. You are the demon Deacon! (Sebaas sauce)
Although the efficiency is nearly doubled, there are still large queues of Changlong ~
This makes the old and the old man uncomfortable! The "Masters" are not so satisfied !~ Ah, I'm so excited.
Bytes -------------------------------------------------------------------------------------
The youngest young master put forward an evil idea at a time of cool afternoon tea:
"Since we only want to watch the maids sauce while drinking tea, and we don't really want her to pour tea, why can't we watch others call the maids sauce while drinking tea ?"
The black tea of all old and young men turned into blood and fog and sprayed on the flawless table.
The young master explained:
Since the data pool is actually a queue and joining a queue is only an operation on the queue header,
The content added to the other end of the accessed node is meaningless for the thread that has started to access the internal content.
How hard is it to lock changes that do not exist?
"Sloga !?"
"Slogs !!"
"Interest !!"
Everyone who got up suddenly realized that they were holding each other's hands excitedly, and then burst into tears ....
But why should we lock it before?
In-depth study of the <t>Source codeWe have learned how to implement the queue <t>: the cyclic queue implemented by the fixed-length array.
If you are not familiar with the circular queue, refer to the article published by Boyou.
Queue <t> executes the following operations each time toarray is used.
Code snippet
-
- PublicT [] toarray ()
-
- {
-
- T [] destinationarray =NewT [This. _ SIZE];
-
- If(This. _ Size! = 0)
-
- {
- If(This. _ Head <This. _ Tail)
-
- {
-
- Array. Copy (This. _ Array,This. _ Head, destinationarray, 0,This. _ Size );
-
- ReturnDestinationarray;
- }
-
- Array. Copy (This. _ Array,This. _ Head, destinationarray, 0,This. _ Array. Length-This. _ Head );
-
- Array. Copy (This. _ Array, 0, destinationarray,This. _ Array. Length-This. _ Head,This. _ Tail );
- }
-
- ReturnDestinationarray;
-
- \
At the same time, when someone is using enqueue, _ SIZE _ head _ tail may be modified concurrently.
Code snippet
-
- Public VoidEnqueue (T item)
-
- {
-
- If(This. _ Size =This. _ Array. length)
- {
-
- IntCapacity = (Int)((This. _ Array. length * 200l)/100l );
-
- If(Capacity <(This. _ Array. Length + 4 ))
-
- {
-
- Capacity =This. _ Array. Length + 4;
- }
-
- This. Setcapacity (capacity );
-
- }
-
- This. _ Array [This. _ Tail] = item;
-
- This. _ Tail = (This. _ Tail + 1) %This. _ Array. length;
- This. _ SIZE ++;
-
- This. _ Version ++;
-
- }
-
-
Too dangerous!
We use the lock to ensure that these key tags are used. This is caused by the limitations of the array kernel itself :(
We first fell into the psychological trap of "queue to use, M $ provides queue,
-- It is a wrong common sense to watch the waitress sauce.
-- It seems that the chat Data Pool cannot be used.
We must implement what Microsoft class libraries cannot do. That's why the maaid sauce. It's the last day that you went to Ouo, Europe, and Europe to drink hiahiahia .....
We look forward to the next article:
Spam list