The first C + + program after work

Source: Internet
Author: User

Multithreading

#include <iostream>#include<pthread.h>//multi-Threaded related operation header file, portable many platformsusing namespacestd;#defineNum_threads 5//Number of Threadsvoid* Say_hello (void*args) {cout<<"Hello ..."<<Endl;} //function Returns a function pointer, which is easy to follow as a parameterintMain () {pthread_t tids[num_threads];//Thread ID     for(inti =0; i < num_threads; ++i) {intret = Pthread_create (&tids[i], NULL, Say_hello, NULL);//parameters: Create thread ID, thread parameter, start address of thread run function, run functionThe Parametersif(Ret! =0)//Create line Cheng return 0{cout<<"pthread_create error:error_code="<< ret <<Endl; }} pthread_exit (NULL); //wait for each thread to exit before the process ends, or the process forces the end and the thread is in an unterminated state}

Compiling g++-o udpbench udpbench.cpp-lpthread

Run./udpbench

The first C + + program after work

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.