C ++ Confused about Threads
source link: https://www.codesd.com/item/c-confused-about-threads.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C ++ Confused about Threads
Basicly this is what I have:
Server::
Server (int port) {
cout << "Initializing server.\n";
(...)
pthread_t newthread;
pthread_create(&newthread, NULL, &Server::_startListening, NULL);
cout << "Exit\n";
pthread_exit(NULL); // <-- Question
}
void* Server::_startListening (void* param) {
cout << "Start listening for clients ...\n";
return 0;
}
Question: If I don't put pthread_exit(NULL); in the code, it will work when I compile it on Linux (Ubuntu) but it won't work on Mac OSX 10.6.2. When I compile and run it on linux it will say Initializing server, Start listening for clients, Exit while on Mac OSX it will say Initializing for server, Exit, Start listening for clients.
The problem seems to occur around the pthread_exit, if I place it above the cout << Exit. That message will never be displayed (how weird is that).
Am I doing something wrong?
you probably intend to use pthread_join rather than exit.
Related Articles
Confusion about threading the work process
confusion about the Android service and the wire
I am confused about the use of the static method in Multithreading Java?
Confused about & ldquo; implements Runnable & rdquo;
Java - Very confusing about this recursive binary tree
Confusion about where to put business logic when using the entity framework
Confusion about java
Confusion about virtual / new / override
Confused about event.type Lua
Visual Studio IDE confused about the meaning of the keyword var
Totally confused about the test of the rails ... What are the tools for which jobs?
Is the Rails application confusing about the environment?
Confused about error handling in VB6 and the use of On Error GoTo
I am confused about JSNI. How and when using JSNI in Google Toolkit
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK