Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Problem with thread function

    I have written a client/server program using pthread. After I get a client connection request, I create a thread for that client(detached thread with system scope).
    The start routine that is specified in the pthread_create function creates a object of a class and calls a function in that class.
    The code looks some what like this ->
    void *start_routine(void *ptr)

    abc object; //abc is a class
    object.func(arg); //func() is a function in the class abc

    When I run this program, the thread is created successfully, all the statements above the function call(in the above routine) executes,but it doesn't return from the function call, nor it executes that function(I have given some cout statements at the begining of the function for checking purpose, which is not printed).
    I haven't used any mutexes or condition variables, since it is not required here. What wrong have I made?

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Täby, Sweden
    First, if you haven't needed any mutexes or anything, it must mean that you sure no or little data between the threads, right? Why not just fork instead?

    Anyway, have you tried looking at what happens with gdb? Is the object's constructor called correctly, and does it return from it?

  3. #3
    Presently I am not using mutexes, as I progress I will use it. I am now just testing the initial steps.
    I tried with gdb, the constructor is called correctly, but it is not executing anything in the function,it just stops there. Is anything to be done with any signals?

  4. $spacer_open
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Täby, Sweden
    Wouldn't think so. What happens at assembly level?

  6. #5
    sorry, There is some problem with the parameters that I pass(Problem with pointers). I just tried it with other function and it worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts