programmer group

pthread_cond_broadcast --- pthread_cond_signal --- pthread_cond_wait difference

1. Applicable to pthread_cond_broadcast 1. One producer has many consumers, and the producer can produce many products at one time. 2. Multiple producers and multiple consumers 3. Implementation of read-write lock (notify all readers after writing) //test.c #include<stdio.h> #include<unistd.h> #include<pthread.h> #define MAX_THREAD_NUM 5 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond =...

programmer group

switch statement usage in C ා

1 not every case needs to contain break. If the case statement is empty, it can not contain break, and the control flow will continue the subsequent case until the break is encountered. char grade = 'C'; switch (grade) { case 'A': case 'B': case 'C': Console.WriteLine("CCC"); break; case 'D': Console.WriteLine("DDD"); break; default: Console.WriteLine("Invalid grades"); break; } Output CCC no matter grad = A or B...

programmer group

Understanding and optimization of recursive function

This article is mainly my summary of recursive learningProblems to be solved with deliveryMeet three conditions: The solution of a problem can be divided into several subproblems This problem is the same as the sub problem after decomposition except for the difference of data scale Recursive termination condition exists Thinking of writing recursive function: analyze the relationship between the problem and the subproblem, find...

programmer group

Vector vector container (summary of commonly used methods)

As for the learning of vector container in STL, it's better to watch the code after compiling and running, and see the execution result at the same time. I still want to say that it's better to watch other people's code 100 times, rather than write it by yourself. Vector vector container can not only access elements randomly like array, but also insert elements in the tail at any time. It is simple and efficient, and can completely...