The Knowledge Summariize in April

xiaoxiao2021-03-05  33

4/15/2005 1. Learn about the difference between BIG-Endian and Little-Endian between different systems. In the UNIX system, it is mainly used to handle data in a BIG-Endian mode, which is caused by Berkeley's historical legacy. But use Little-Endian mode in the Windows system. 2. Further understand 2 binary, 10, and 16-based fast conversion. 2-> 16: 1 = 8 of 1 = 8, 2 binary in 4Bit, 1 = 4, ten digits 1 = 2, 1 = 1 in the bit, the number of digits The number of converted is added, and the number of 10 is 0-15. EG. 1001, 1101 -> 9d 10-> 16: If x> 15 and x <256: Algorithm is divided by 16 additions. Eg. 100-> 64. 16-> 10: The algorithm is multiplied by 16 plus a bit number. EG. 5E, converted into 10 credits 104. Note that larger digital counter is calculated.

4/18/20051. Temperature and multi-thread probability, deepen understanding it. Synchronization Event, WaitForSingleObject1) Event comprising CreateEvent, // generate an Event Handle SetEvent, // to Single Event ResetEvent, // to UnSingle Event PulseEvent, tired after // Single Event, immediately close UnSingle Event CloseEvent // Event 2) WaitForSingleObject to Check EVENT object is in what state. If it is a Singal state, the WaitForsingleObject is immediately ended, and then the next instruction is then performed. If it is an unsingal state, WaitForsingleObject will wait until Thread turns the EVENT object state into a Singal state or Timeout executes the next instruction. Here is a language description with an image: it is better than traffic lights. The CreateEvent has a traffic light. All Singal status, indicate green light, any thread can pass WaitForsingleObject. And unsignal represents red lights. Not available. Any thread cannot pass in WaitForsingleObject. Only waiting for the green light, or Time Out.

2. Know the HEAP, Stack 1) Global variables, New, Malloc, etc. Allocated in HEAP. 2) If the memory is allocated in the function, you want to use after the function returns, use new, malloc, or defined to static variables, static variables are in Heap. 3) If a variable is created on the Stack, when the program runs to the left "}" 0 containing the minimum {} pair defined by this variable, the variable will be cleared. And the variable created on the HEAP is only explicitly called Delete or is cleared when the program runs. 4) A thread cannot access the Stack of another thread. And Heap is shared in all threads in the process. Eg. CMYCLASS HEHE; // This is CMYCLASS * HEHE on the stack (STACK); // This is on the heap (HEAP)

3) Understand the Socket I / O model - SELECT model sees a metaphor of an image online to describe the Socket I / O model: Lao Chen has a daughter working in the field, can't come back frequently, Lao Chen and she contact her. Their letter will be delivered to their mailbox by the postman. This is very similar to the Socket model. Below I will explain the Socket I / O model as an example of the reception letter ~~~ Lao Chen wants to see daughter's letter. So, every 10 minutes will check the mailbox, see if there is a daughter's letter ~~~~~ In this case, "downstairs check the mailbox" and then returned to the upstairs to delay the time, So old Chen can't do other work. The SELECT model and the old Chen's situation are very similar: the week is beginning to check ... If there is data ... Receive / send ....... where select is a bit like waitforsingleObject, when there is a signal Or timeout, you will go. Otherwise I have been waiting. Some important macros: FD_ZERO, FD_SET, FD_ISSET. eg.while (TRUE) {// Prepare the Read and Write socket sets for network I / O notification FD_ZERO (& ReadSet);. FD_ZERO (& WriteSet);. // Always look for connection attempts FD_SET (ListenSocket, & ReadSet); // Set Read and Write Notification for Each Socket Based on The // Current State The Buffer. If The = 0; i = 0; i BYTESRECV> SocketArray [i] -> Bytessend fd_set (socketArray [i] -> socket, & writeet); else fd_set (SocketArray [i] -> socket, & readset;

IF ((Total = SELECT, & WRITESET, NULL, NULL) == Socket_ERROR) {Printf ("SELECT () Returned with Error% D / N", wsagetlasterror (); return;} // check for arriving connections on the listening socket if (FD_ISSET (ListenSocket, & ReadSet)) {Total--;. if (! (AcceptSocket = accept (ListenSocket, NULL, NULL)) = INVALID_SOCKET) {// Set the accepted socket to non-blocking mode so the server will // not get caught in a blocked condition on WSASends NonBlock = 1; if (ioctlsocket (AcceptSocket, FIONBIO, & NonBlock) == SOCKET_ERROR) {printf ( "ioctlsocket () failed with error% d / n", Wsagetlasterror ()); return;}} == false) Return;}} // check each socket for read and write notification unsteil the Number // of sockets in total is satisfied. for (i = 0; Total> 0 && i socket, & readset) {wsarecv (...); ... .} // if the writeset is marked on this socket dam.............................. ..} / 19/20051. Learn Mutex's use. If more than 2 threads want to modify the shared data, only one thread can do an UPDATE action, and other threads can be read or modified after this thread is completed, this is used for Mutex technology. .

The practices and features of the Mutex object are as follows: Use createmutex () to generate a MUTEX object, and the incoming MUTEX name string is used to distinguish the different MUTEX, that is, no matter which process / thread, as long as the incoming name parameter Is the same string, the createmutex () transmitted value (hmutex, handle of mutex) points to the same MUTEX object. This is the same as the EVENT object. However, Mutex and Event have a big difference, Mutex has Owner's concept, if Mutex is owned by Threada, then THREADA performs WaitForsingleObject (), it will not stop, and will immediately pass Wait_Object_0, and other Thread execute WaitForsingleObject ( Then, it will stop until the ownership of Mutex is released by Release or Time Out. 1.Createmutex (NULL, 1, "MyMutex") The second parameter pass 1, then the first call CREATEMUTEX and the thread of the second parameter pass 1 will own the MUTEX. But if the second parameter passes 0, when CreateMutex is written, no one has the MUTEX. 2. Instructions, if the Mutex does not have the owner, the first call waitforsingleObject's Thread will own the MUTEX. The above says that only the Mutex's Thread does not stop, other Thread will stop, how do other Thread get the ownership of the MUTEX? It must be the original three-owned Thread with ReleaseMutex to give up ownership, once all rights are disconnected, and other Thread is in WaitForsingleObject () stay wait state, there is a Thread that acquires the mutex ownership in real time (top 2 points Description), so if other Thread also perform WaitForsingleObject (), it will be in the waiting state. For WaitForsingleObject () will make Mutex in the state of Unsignal (different from Event), so you can complete the same time asking only a trie to Update Sharing Memory (Of course, everyone should use Mutex rules to do, you want Update To use WaitForsingleObject () to see if you can get the ownership of Mutex. To give up MUTEX's power, this is different from Event, and Non-Mutex owner calls ReleaseMuteMuteMut does not have any effect. Each time you call at WaitforsingleObject, Mutex will have a counter that will be added. ReleaseMutex success will be reduced. After the Mutex's counter is 0, the system will remove it.

转载请注明原文地址:https://www.9cbs.com/read-35431.html

New Post(0)