Skip to content
Snippets Groups Projects
Commit c72e7f1f authored by Thierno souleymane Bah's avatar Thierno souleymane Bah
Browse files

fix(issue concerning ctx fixed, now finish correctly)

parent 14d1d975
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ int main(int argc, char *argv[]) ...@@ -16,7 +16,7 @@ int main(int argc, char *argv[])
printf("Begin \n"); printf("Begin \n");
yield(); yield();
printf("End \n"); printf("End \n");
exit(EXIT_SUCCESS); return EXIT_SUCCESS;
} }
void f_ping(void *args) void f_ping(void *args)
......
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <assert.h> #include <assert.h>
#include "try.h" #include "try.h"
...@@ -43,6 +44,21 @@ int init_ctx(ctx_t *pctx, int stack_size, funct_t f, void *args) ...@@ -43,6 +44,21 @@ int init_ctx(ctx_t *pctx, int stack_size, funct_t f, void *args)
void switch_to_ctx(ctx_t *pctx) void switch_to_ctx(ctx_t *pctx)
{ {
if (pctx->status == CTX_END)
{
// Si c'est l'unique ctx
if (pctx == pctx->next_ctx)
ring_ctx = NULL;
else
current_ctx->next_ctx = pctx->next_ctx;
free(pctx->stack);
free(pctx);
yield();
return;
}
assert(pctx->status != CTX_END); assert(pctx->status != CTX_END);
if (current_ctx != NULL) if (current_ctx != NULL)
{ {
...@@ -93,7 +109,13 @@ ctx_t *create_ctx(int stack_size, funct_t f, void *args) ...@@ -93,7 +109,13 @@ ctx_t *create_ctx(int stack_size, funct_t f, void *args)
void yield() void yield()
{ {
assert(ring_ctx != NULL || current_ctx != NULL); //printf("%p, %p\n", current_ctx, ring_ctx);
if (ring_ctx == NULL)
{
printf("\nEnd \n");
exit(EXIT_SUCCESS);
}
if (current_ctx == NULL) if (current_ctx == NULL)
switch_to_ctx(ring_ctx->next_ctx); switch_to_ctx(ring_ctx->next_ctx);
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment