Hello ,
I am trying to create threads using makecontext function.
The code is sth like this..
#include "mythread.h"
#include <malloc.h>
#include <stdio.h>
#define FIBER_STACK 1024*64
int mythread_create(mythread_t *new_thread_ID,
mythread_attr_t *attr,
void * (*start_func)(void *),
void *arg)
{
// Get the current execution context
mythread_t t2;
t2 = (mythread_t)new_thread_ID;
getcontext(&t2->context);
// Modify the context to a new stack
t2->context.uc_link = 0;
t2->context.uc_stack.ss_sp = malloc( FIBER_STACK );
t2->context.uc_stack.ss_size = FIBER_STACK;
t2->context.uc_stack.ss_flags = 0;
if ( t2->context.uc_stack.ss_sp == 0 )
{
perror( "malloc: Could not allocate stack" );
return 0;
}
// Create the new context
printf( "Creating child fiber\n" );
t2->start_func = start_func;
makecontext(&t2->context,[B][U]<--------------->[/U][/B],0);
printf("make context");
}
void * display()
{
printf ("Hello");
}
int main()
{
mythread_t t1;
mythread_create(&t1,NULL,display,NULL);
return 0;
}
/* end of code */
my problem lies in the 2nd argument of the makecontext function as to how to pass the function pointer.(In red)
I am getting a segmentation fault too.
Please help..