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* ...
- 05-22-2010 #1Just 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).
that works fine. However, when I move display_prompt to UI.hCode:#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; }
no "Hello111 " output is printed.
anyone knows how to solve that?
Elad
- 05-23-2010 #2
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):
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!
- 05-23-2010 #3Just 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;
}
- 05-23-2010 #4
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.
- 05-23-2010 #5
Both are perfectly valid: The C Preprocessor - Include Syntax .
- 05-24-2010 #6Just 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 ?
- 05-24-2010 #7


Reply With Quote
