5

C ++ Confused about Threads

 3 years ago
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.
neoserver,ios ssh client

C ++ Confused about Threads

advertisements

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

Try open the following page in two different tabs in your browser. hit the refresh button to avoid getting the page from browser cache : protected void Page_Load(object sender, EventArgs e) { Thread.Sleep(10000); Response.Write(DateTime.Now.ToString(

confusion about the Android service and the wire

I'm new to Android and I've been quite confused about the life time of service and thread. Let's say I have an activity and it starts a service in a worker thread by calling startService(). According to Google documentations, the service will run ind

I am confused about the use of the static method in Multithreading Java?

something about static: instances of class share static method the similar questions: Java: when to use static methods What does the 'static' keyword do in a class? I am confusing about: static method just have only one memory block? if i use static

Confused about & ldquo; implements Runnable & rdquo;

Hello have only a few days with Java and android here. I am a bit confused about exactly how the "implements runnable" actually works example: public class DrawableSurfaceView extends SurfaceView implements Runnable { [...] public void resume(){

Java - Very confusing about this recursive binary tree

I'll mention that this is for homework. I'm incredibly confused about what I need to do to get this add() function to work. The confusing part is that we are required to define left and right child as type BinaryTree, and have the add() function take

Confusion about where to put business logic when using the entity framework

I've just started working with the Entity framework and I'm confused about how the classes normally in the business layer fit in with the entities that are created by the Entity Framework. When working with classic ADO.NET, I would have a class calle

Confusion about java

I have some confusion about java. Java is compiler or interpreter language. I got some link which has some great description but the confusion is some one says java is compiled language or some of them are says java is interpreter language? Even how

Confusion about virtual / new / override

I am a bit confused about the virtual/new/override thing. Here's an example: class A { public virtual void mVVirtual() { Console.WriteLine("A::mVVirtual"); } } class B : A { public virtual void mVVirtual() { Console.WriteLine("B::mVVirtual&

Confused about event.type Lua

I'm working from a book and learning about orientation. I'm very confused about the code event.type. Here's the code from the book: portrait = display.newText ("Portrait", display.contentWidth / 2,display.contentHeight / 2, nil,20) portrait: set

Visual Studio IDE confused about the meaning of the keyword var

Consider the following simple program: static class Program { static void Main() { } static void Method(short? x) { const int y = 50; // note: is Int32, but is const and within Int16 range var z = x ?? y; // note: var keyword used; IDE is confused ab

Totally confused about the test of the rails ... What are the tools for which jobs?

I'm learning Rails after a long time manually testing my own .NET code, I'm loving what ive seen but i am SO confused about how it all fits together! So my questions are 1 - Where would i use: Rspec Cucumber Test Unit Shoulda Selenium (not really a r

Is the Rails application confusing about the environment?

I created a new Ruby on Rails app (first app I'm working on in Rails 3), and for some reason, my app seems to be confused about what environment it should be running in (unless I'm just confused). When I run rake db:create, it's creating both the "my

Confused about error handling in VB6 and the use of On Error GoTo

I'm needing to troubleshoot some old VB6 code and I'm confused about the use of "On Error". In the sample below, if I surround the specific line of code I want to test with the On Error GoTo and the ErrHandler1, is that the ONLY line that's test

I am confused about JSNI. How and when using JSNI in Google Toolkit

I am new Google web toolkit.I am confused about JSNI.Why and when use of JSNI in Google web toolkit.Advantage and limitation of JSNI.Thanks in advance.I use native Javascript code when there is no other way of coding the feature other than in Javascr

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK