What is pthread H on Linux
Thread with C ++ on Linux
This would be a correct example.
Okay, I have to pick it up now, because even in the corrected state this is a "lousy" style.
C includes have no place in C ++! Therefore ...
You should always use the C ++ variant of a C include, if available. Otherwise an "extern C" should be used around it.
Variables always miss an initial value!
The difference between C ++ and C in the case of the GCC (with its C99 standard) is that the GCC in the case of C initializes the variables with a default value (thanks to the kernel developers, who put a lot of pressure on the GCC developers ). Unfortunately, this does not apply to C ++ (g ++ or gcc -lstdc ++). In addition, the RAII principle (Resource Allocation is Initialization) applies in C ++ anyway ...
After creating a thread, the further procedure must be determined.
It all depends on what attributes the thread was created with. Either joinable or not. Then you MUST detach or join the thread (pthread_detach = pthread_raise_zombie: D), otherwise the behavior is undefined. With a detach you release the thread into the wild, so you can no longer get to it. So one has to make sure that it ends normally before the comprehensive process ends. A join waits for the thread to return normally. Is basically something like a "wait_for_thread" ...
Very important: If you have a GCC 4.4 or larger available, there is a high probability that the StdC ++ Lib Version 4 is included and it contains native C ++ threads. You should definitely use them, because pthreads are for C and not for C ++. The signal concept in pthreads struggles with C ++ exceptions.
Here is a C ++ 0x example.
You don't necessarily have to use a LockGuard, but it is best for this example because "cout" is used several times once. You can take out the LockGuard for a gag ... looks funny
It is compiled with "g ++ -std = c ++ 0x -lpthread ..." pthrads is a fallacy here, some remainder is probably used, because the native C ++ threads are not based on pthreads but on kernel threads.
- How do AWS Application Load Balancers work
- Is there an inflation on the stock exchange
- What big names are against crypto
- How does water come from frogs
- Population in North Carolina
- Should the law impose morality
- What is the correct definition of tragedy
- How much should someone enjoy their work
- Are Haydn's piano sonatas better than Mozart's
- What is strict and vicarious liability
- How often are new habitable islands formed
- What is a TVL strand
- What is a capillary
- What's the deal with Instagram Facebook crashes
- Why explore the oceans rather than space
- WebRTC requires a server
- How we can read human psychology
- What is the difference between cancellation and cancellation
- What is considered an experience on a resume
- Why was sugar rationed during World War I.
- What is the pH for ammonia
- Which college is better ABESEC or IMS
- What are parameters for the design of the road
- What makes no sense to your friends