Find the answer to your Linux question:
Results 1 to 7 of 7
Hi all, I wrote some code in c, using pthread (I configured the linker and compiler in eclipse IDE first). Code: #include <pthread.h> #include "starter.h" #include "UI.h" Page* MM; Page* ...
  1. #1
    Just Joined!
    Join Date
    May 2010
    Posts
    1

    remote function with pthread

    Hi all,

    I wrote some code in c, using pthread (I configured the linker and compiler in eclipse IDE first).

    Code:
    #include <pthread.h>
    #include "starter.h"
    #include "UI.h"
    
    Page* MM;
    Page* Disk;
    PCB* all_pcb_array;
    
    void* display_prompt(void *id){
    
        printf("Hello111\n");
    
        return NULL;
    }
    
    
    int main(int argc, char** argv) {
        printf("Hello\n");
        pthread_t *thread = (pthread_t*) malloc (sizeof(pthread_t));
        pthread_create(thread, NULL, display_prompt, NULL);
        printf("Hello\n");
        return 1;
    }
    that works fine. However, when I move display_prompt to UI.h
    no "Hello111 " output is printed.

    anyone knows how to solve that?
    Elad

  2. #2
    Just Joined! computer_freak_8's Avatar
    Join Date
    Sep 2008
    Location
    Des Moines, Iowa, USA
    Posts
    54
    This might end up being a post-and-run (I'm not very familiar with programming), but I noticed some syntax that might be causing some issue(s):
    Quote Originally Posted by elad2109 View Post
    Code:
    #include <pthread.h>
    #include "starter.h"
    #include "UI.h"
    The first one you used less-than/greater-than; the next two you use double-quotes.

    Maybe? I don't know.. just an idea. Good luck!

  3. #3
    Just Joined!
    Join Date
    Jan 2006
    Posts
    3
    Hello !
    With this I compiled+linked
    and it worked.
    I think u misused pthread_create as pthread_create initializes a struct for u, u have to give it a reference to that struct !
    what do u mean by "put it in UI.h" ?

    #include <stdlib.h>
    #include <stdio.h>
    #include <pthread.h>


    void* display_prompt(void *id){

    printf("Hello111\n");

    return NULL;
    }


    int main(int argc, char** argv) {
    pthread_t thread;
    int rc;

    printf("Hello\n");
    rc= pthread_create( &thread, NULL, display_prompt, NULL);
    printf("Hello\n");
    return 1;
    }

  4. #4
    Linux Newbie unlimitedscolobb's Avatar
    Join Date
    Jan 2008
    Posts
    120
    Quote Originally Posted by elad2109 View Post
    that works fine. However, when I move display_prompt to UI.h
    no "Hello111 " output is printed.
    Please do attach your main file and UI.h after you have moved the function to the other header file so that we can tell something certain instead of guessing.

    As a quick idea I'd suggest to try to directly invoke your display_prompt after you have moved it to UI.h. That is, don't create a thread for it, just call display_prompt and see what happens.

    drlapiano, please note, that your code is essentially the same as elad2109's original code. You create your variable locally and the OP mallocs it in the heap, but pthread_create should see no difference.

  5. #5
    Linux Newbie unlimitedscolobb's Avatar
    Join Date
    Jan 2008
    Posts
    120
    Quote Originally Posted by computer_freak_8 View Post
    The first one you used less-than/greater-than; the next two you use double-quotes.
    Both are perfectly valid: The C Preprocessor - Include Syntax .

  6. #6
    Just Joined!
    Join Date
    Jan 2006
    Posts
    3
    oops! of cours u'r right ! probably read too quikly !
    But I build a header containing that function (bizarre idea ... )... and it worked the same ... I should say of course !
    But it was probably not the same UI.h as elad2109's ?

  7. #7
    Linux Newbie unlimitedscolobb's Avatar
    Join Date
    Jan 2008
    Posts
    120
    Quote Originally Posted by drlapiano View Post
    But I build a header containing that function (bizarre idea ... )... and it worked the same ... I should say of course !
    But it was probably not the same UI.h as elad2109's ?
    This is why I asked elad2109 for the modified files

Posting Permissions

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