Compare commits
No commits in common. "c06e17a43964f3ef15b6149bcc2970228342ea2c" and "9fd93710a18589e299169f07a1140f52801f887c" have entirely different histories.
c06e17a439
...
9fd93710a1
34
Makefile
34
Makefile
@ -5,8 +5,8 @@ install_dir?=install
|
||||
|
||||
# Comment out the bins that doesn't need to be compiled
|
||||
bbins+=$(wildcard ${tst_dir}/*.c)
|
||||
bins=$(filter-out ${tst_dir}/51-fibonacci.c ${tst_dir}/71-preemption.c ${tst_dir}/63-mutex-equity.c ${tst_dir}/64-mutex-join.c, ${bbins})
|
||||
all_bins=01-main 02-switch 03-equity 11-join 12-join-main 13-join-switch 21-create-many 22-create-many-recursive 23-create-many-once 31-switch-many 32-switch-many-join 33-switch-many-cascade 51-fibonacci 52-dac-sum 61-mutex 62-mutex 63-mutex-equity 64-mutex-join 71-preemption 81-deadlock
|
||||
bins=$(filter-out ${tst_dir}/51-fibonacci.c ${tst_dir}/71-preemption.c, ${bbins})
|
||||
all_bins=01-main 02-switch 03-equity 11-join 12-join-main 21-create-many 22-create-many-recursive 23-create-many-once 31-switch-many 32-switch-many-join 33-switch-many-cascade 51-fibonacci 52-dac-sum 61-mutex 62-mutex 63-mutex-equity 64-mutex-join 71-preemption 81-deadlock
|
||||
|
||||
bins_target=$(patsubst %.c,${build_dir}/%,${bins})
|
||||
install_bins_targets=$(patsubst ${tst_dir}/%.c,${install_dir}/bin/%,${bins})
|
||||
@ -45,11 +45,11 @@ srcs+=$(wildcard ${src_dir}/*.c ${src_dir}/**/*.c)
|
||||
headers+=$(wildcard ${src_dir}/*.h ${src_dir}/**/*.h)
|
||||
objs+=$(patsubst %.c,${build_dir}/%.o,${srcs})
|
||||
|
||||
PHONY += all
|
||||
.PHONY: all
|
||||
all: ${all_targets}
|
||||
${RM} .lastpthread # Set that the last build was without pthread
|
||||
|
||||
PHONY += install
|
||||
.PHONY: install
|
||||
install: build ${install_bins_targets} ${install_dir}/lib/libthread.so ${install_dir}/lib/libthread.a
|
||||
|
||||
${install_dir}/lib/libthread.so: ${build_dir}/libthread.so
|
||||
@ -64,21 +64,21 @@ ${install_bins_targets}: ${install_dir}/bin/%: ${build_dir}/${tst_dir}/%
|
||||
@mkdir -p $(dir $@)
|
||||
install $^ $@
|
||||
|
||||
PHONY += graphs
|
||||
.PHONY: graphs
|
||||
graphs:
|
||||
cd graphs && bash generate_graphs.sh
|
||||
|
||||
PHONY += valgrind
|
||||
.PHONY: valgrind
|
||||
valgrind: ${valgrind_targets}
|
||||
|
||||
PHONY += ${valgrind_targets}
|
||||
.PHONY: ${valgrind_targets}
|
||||
${valgrind_targets}: valgrind_%: ${build_dir}/${tst_dir}/%
|
||||
valgrind $^ ${check_argv} --leak-check=full --show-reachable=yes --track-origins=yes
|
||||
|
||||
PHONY += build
|
||||
.PHONY: build
|
||||
build: ${bins_target} ${build_dir}/libthread.so ${build_dir}/libthread.a ${build_dir}/${tst_dir}/51-fibonacci ${build_dir}/${tst_dir}/71-preemption
|
||||
|
||||
PHONY += debug
|
||||
.PHONY: debug
|
||||
debug:
|
||||
$(MAKE) USE_DEBUG=. build
|
||||
|
||||
@ -95,12 +95,6 @@ ${check_targets}: check_%: ${build_dir}/${tst_dir}/%
|
||||
$^ ${check_argv}
|
||||
|
||||
${bins_target}: ${build_dir}/%: ${objs} ${build_dir}/%.o
|
||||
${CC} -o $@ $^ ${CFLAGS} ./lib/libmimalloc ${LDFLAGS} -DSMALL_OPTI
|
||||
|
||||
${build_dir}/${tst_dir}/63-mutex-equity: ${objs} ${build_dir}/${tst_dir}/63-mutex-equity.o
|
||||
${CC} -o $@ $^ ${CFLAGS} ./lib/libmimalloc ${LDFLAGS}
|
||||
|
||||
${build_dir}/${tst_dir}/64-mutex-join: ${objs} ${build_dir}/${tst_dir}/64-mutex-join.o
|
||||
${CC} -o $@ $^ ${CFLAGS} ./lib/libmimalloc ${LDFLAGS}
|
||||
|
||||
${build_dir}/${tst_dir}/51-fibonacci: ${build_dir}/src/thread/thread_fibo.o ${build_dir}/${tst_dir}/51-fibonacci.o ${build_dir}/src/utils/ufd.o
|
||||
@ -127,20 +121,18 @@ ${build_dir}/%.o: %.c
|
||||
@mkdir -p $(dir $@)
|
||||
${CC} -o $@ -c $^ ${CFLAGS}
|
||||
|
||||
PHONY += compile_flags.txt
|
||||
.PHONY: compile_flags.txt
|
||||
compile_flags.txt:
|
||||
(echo "${CFLAGS} ${LDFLAGS}" | sed 's/ /\n/g') > compile_flags.txt
|
||||
|
||||
PHONY += format
|
||||
.PHONY: format
|
||||
format:
|
||||
clang-format -i ${srcs} ${headers}
|
||||
|
||||
PHONY += check_format
|
||||
.PHONY: check_format
|
||||
check_format:
|
||||
clang-format --dry-run --Werror ${srcs} ${headers}
|
||||
|
||||
PHONY += clean
|
||||
.PHONY: clean
|
||||
clean:
|
||||
${RM} -r build install
|
||||
|
||||
.PHONY: $(PHONY)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
tst_dir=tst
|
||||
filenames="01-main 02-switch 03-equity 11-join 12-join-main 13-join-switch 21-create-many 22-create-many-recursive 23-create-many-once 31-switch-many 32-switch-many-join 33-switch-many-cascade 51-fibonacci 61-mutex 62-mutex 63-mutex-equity 64-mutex-join 71-preemption 81-deadlock"
|
||||
filenames="01-main 02-switch 03-equity 11-join 12-join-main 21-create-many 22-create-many-recursive 23-create-many-once 31-switch-many 32-switch-many-join 33-switch-many-cascade 51-fibonacci 61-mutex 62-mutex 63-mutex-equity 64-mutex-join 71-preemption 81-deadlock"
|
||||
mkdir -p "${tst_dir}"
|
||||
|
||||
for filename in ${filenames}
|
||||
|
@ -33,7 +33,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef STACK_SIZE
|
||||
#define STACK_SIZE 4 * 1024
|
||||
#define STACK_SIZE 1024
|
||||
#endif
|
||||
|
||||
// Variables used to clean up everything at the end of the processus
|
||||
@ -73,11 +73,6 @@ int thread_yield(void)
|
||||
if (TAILQ_EMPTY(&scheduler_fifo))
|
||||
return 0;
|
||||
|
||||
#ifdef SMALL_OPTI
|
||||
if (!IS_FINISHED(running) && !IS_WAITING(running) && !IS_MUTEX_WAITING(running))
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if (HAS_STATUS(running, MUTEX_LOCKING)) {
|
||||
if (running->mutex_prio > 0) {
|
||||
running->mutex_prio--;
|
||||
|
@ -1,13 +1,10 @@
|
||||
#include "ufd.h"
|
||||
#include "debug.h"
|
||||
#include "stdlib.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
|
||||
inline void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread)
|
||||
void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread)
|
||||
{
|
||||
TAILQ_INIT(&ufd->children);
|
||||
ufd->thread = thread;
|
||||
ufd->repr = ufd,
|
||||
ufd->parent = NULL;
|
||||
@ -15,48 +12,35 @@ inline void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread)
|
||||
}
|
||||
|
||||
|
||||
inline void ufd__join(struct ufd_t* th1, struct ufd_t* th2)
|
||||
void ufd__join(struct ufd_t* th1, struct ufd_t* th2)
|
||||
{
|
||||
struct ufd_t* a = ufd__find(th1);
|
||||
struct ufd_t* b = ufd__find(th2);
|
||||
|
||||
if (a != b)
|
||||
{
|
||||
th1->parent = th2;
|
||||
th1->repr = b;
|
||||
th2->child = th1;
|
||||
if (th1 != b)
|
||||
TAILQ_INSERT_TAIL(&b->children, th1, link);
|
||||
a->parent = th2;
|
||||
a->repr = b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline struct ufd_t* ufd__find(struct ufd_t* th)
|
||||
struct ufd_t* ufd__find(struct ufd_t* th)
|
||||
{
|
||||
if (th->repr == th)
|
||||
return th;
|
||||
|
||||
struct ufd_t* nrepr = ufd__find(th->repr);
|
||||
TAILQ_REMOVE(&th->repr->children, th, link);
|
||||
TAILQ_INSERT_TAIL(&nrepr->children, th, link);
|
||||
th->repr = nrepr;
|
||||
return nrepr;
|
||||
}
|
||||
|
||||
|
||||
inline void ufd__delete(struct ufd_t* th)
|
||||
void ufd__delete(struct ufd_t* th)
|
||||
{
|
||||
struct ufd_t* child;
|
||||
|
||||
while (!TAILQ_EMPTY(&th->children))
|
||||
if (th->child != NULL)
|
||||
{
|
||||
child = TAILQ_FIRST(&th->children);
|
||||
TAILQ_REMOVE(&th->children, child, link);
|
||||
|
||||
child->parent = th->child;
|
||||
child->repr = th->child;
|
||||
if (child != th->child)
|
||||
TAILQ_INSERT_TAIL(&th->child->children, child, link);
|
||||
th->child->parent = th->child;
|
||||
th->child->repr = th->child;
|
||||
}
|
||||
DBG("prefix %d", a);
|
||||
}
|
||||
|
@ -2,21 +2,15 @@
|
||||
#define _UNION_FIND_H_
|
||||
#include <sys/queue.h>
|
||||
|
||||
TAILQ_HEAD(ufd_children_t, ufd_t);
|
||||
|
||||
// union find delete data structure
|
||||
struct ufd_t {
|
||||
struct ufd_t* parent;
|
||||
struct ufd_t* repr;
|
||||
struct ufd_t* child;
|
||||
struct context_entry_t* thread;
|
||||
struct ufd_children_t children;
|
||||
TAILQ_ENTRY(ufd_t) link;
|
||||
};
|
||||
|
||||
|
||||
struct ufd_t ufd__make_set(struct context_entry_t* thread);
|
||||
|
||||
void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread);
|
||||
|
||||
/*
|
||||
|
@ -1,44 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "thread.h"
|
||||
|
||||
/* test du join d'un thread qui fait plein de yield().
|
||||
*
|
||||
* le programme doit retourner correctement.
|
||||
* valgrind doit être content.
|
||||
*
|
||||
* support nécessaire:
|
||||
* - thread_create()
|
||||
* - thread_exit()
|
||||
* - thread_join() avec récupération valeur de retour, avec thread_exit()
|
||||
* sur un thread qui yield() plusieurs fois vers celui qui joine.
|
||||
*/
|
||||
|
||||
static void * thfunc(void *dummy __attribute__((unused)))
|
||||
{
|
||||
unsigned i;
|
||||
for(i=0; i<10; i++) {
|
||||
printf(" le fils yield\n");
|
||||
thread_yield();
|
||||
}
|
||||
thread_exit((void*)0xdeadbeef);
|
||||
return NULL; /* unreachable, shut up the compiler */
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
thread_t th;
|
||||
int err;
|
||||
void *res = NULL;
|
||||
|
||||
err = thread_create(&th, thfunc, NULL);
|
||||
assert(!err);
|
||||
|
||||
printf("le main joine...\n");
|
||||
err = thread_join(th, &res);
|
||||
assert(!err);
|
||||
assert(res == (void*) 0xdeadbeef);
|
||||
|
||||
printf("join OK\n");
|
||||
return 0;
|
||||
}
|
@ -7,8 +7,7 @@
|
||||
|
||||
/* test de plein de switch pendant que N-1 threads sont bloqués dans join
|
||||
*
|
||||
* La durée du programme doit etre proportionnelle au nombre de yields
|
||||
* mais ne pas varier avec le nombre de threads donné en argument.
|
||||
* La durée du programme doit etre proportionnelle au nombre de threads et de yields donnés en argument
|
||||
*
|
||||
* support nécessaire:
|
||||
* - thread_create()
|
||||
|
Loading…
x
Reference in New Issue
Block a user