Compare commits
10 Commits
9fd93710a1
...
c06e17a439
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c06e17a439 | ||
![]() |
3ad5dc1257 | ||
![]() |
7476ccc821 | ||
![]() |
93a4b1341c | ||
![]() |
e292bd7797 | ||
![]() |
0639823009 | ||
![]() |
7a1ab1415a | ||
![]() |
6d97e0ee60 | ||
![]() |
1505a4d8ef | ||
![]() |
54f03c9e70 |
34
Makefile
34
Makefile
@ -5,8 +5,8 @@ install_dir?=install
|
|||||||
|
|
||||||
# Comment out the bins that doesn't need to be compiled
|
# Comment out the bins that doesn't need to be compiled
|
||||||
bbins+=$(wildcard ${tst_dir}/*.c)
|
bbins+=$(wildcard ${tst_dir}/*.c)
|
||||||
bins=$(filter-out ${tst_dir}/51-fibonacci.c ${tst_dir}/71-preemption.c, ${bbins})
|
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 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
|
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_target=$(patsubst %.c,${build_dir}/%,${bins})
|
bins_target=$(patsubst %.c,${build_dir}/%,${bins})
|
||||||
install_bins_targets=$(patsubst ${tst_dir}/%.c,${install_dir}/bin/%,${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)
|
headers+=$(wildcard ${src_dir}/*.h ${src_dir}/**/*.h)
|
||||||
objs+=$(patsubst %.c,${build_dir}/%.o,${srcs})
|
objs+=$(patsubst %.c,${build_dir}/%.o,${srcs})
|
||||||
|
|
||||||
.PHONY: all
|
PHONY += all
|
||||||
all: ${all_targets}
|
all: ${all_targets}
|
||||||
${RM} .lastpthread # Set that the last build was without pthread
|
${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: build ${install_bins_targets} ${install_dir}/lib/libthread.so ${install_dir}/lib/libthread.a
|
||||||
|
|
||||||
${install_dir}/lib/libthread.so: ${build_dir}/libthread.so
|
${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 $@)
|
@mkdir -p $(dir $@)
|
||||||
install $^ $@
|
install $^ $@
|
||||||
|
|
||||||
.PHONY: graphs
|
PHONY += graphs
|
||||||
graphs:
|
graphs:
|
||||||
cd graphs && bash generate_graphs.sh
|
cd graphs && bash generate_graphs.sh
|
||||||
|
|
||||||
.PHONY: valgrind
|
PHONY += valgrind
|
||||||
valgrind: ${valgrind_targets}
|
valgrind: ${valgrind_targets}
|
||||||
|
|
||||||
.PHONY: ${valgrind_targets}
|
PHONY += ${valgrind_targets}
|
||||||
${valgrind_targets}: valgrind_%: ${build_dir}/${tst_dir}/%
|
${valgrind_targets}: valgrind_%: ${build_dir}/${tst_dir}/%
|
||||||
valgrind $^ ${check_argv} --leak-check=full --show-reachable=yes --track-origins=yes
|
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
|
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:
|
debug:
|
||||||
$(MAKE) USE_DEBUG=. build
|
$(MAKE) USE_DEBUG=. build
|
||||||
|
|
||||||
@ -95,6 +95,12 @@ ${check_targets}: check_%: ${build_dir}/${tst_dir}/%
|
|||||||
$^ ${check_argv}
|
$^ ${check_argv}
|
||||||
|
|
||||||
${bins_target}: ${build_dir}/%: ${objs} ${build_dir}/%.o
|
${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}
|
${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
|
${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
|
||||||
@ -121,18 +127,20 @@ ${build_dir}/%.o: %.c
|
|||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
${CC} -o $@ -c $^ ${CFLAGS}
|
${CC} -o $@ -c $^ ${CFLAGS}
|
||||||
|
|
||||||
.PHONY: compile_flags.txt
|
PHONY += compile_flags.txt
|
||||||
compile_flags.txt:
|
compile_flags.txt:
|
||||||
(echo "${CFLAGS} ${LDFLAGS}" | sed 's/ /\n/g') > compile_flags.txt
|
(echo "${CFLAGS} ${LDFLAGS}" | sed 's/ /\n/g') > compile_flags.txt
|
||||||
|
|
||||||
.PHONY: format
|
PHONY += format
|
||||||
format:
|
format:
|
||||||
clang-format -i ${srcs} ${headers}
|
clang-format -i ${srcs} ${headers}
|
||||||
|
|
||||||
.PHONY: check_format
|
PHONY += check_format
|
||||||
check_format:
|
check_format:
|
||||||
clang-format --dry-run --Werror ${srcs} ${headers}
|
clang-format --dry-run --Werror ${srcs} ${headers}
|
||||||
|
|
||||||
.PHONY: clean
|
PHONY += clean
|
||||||
clean:
|
clean:
|
||||||
${RM} -r build install
|
${RM} -r build install
|
||||||
|
|
||||||
|
.PHONY: $(PHONY)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
tst_dir=tst
|
tst_dir=tst
|
||||||
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"
|
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"
|
||||||
mkdir -p "${tst_dir}"
|
mkdir -p "${tst_dir}"
|
||||||
|
|
||||||
for filename in ${filenames}
|
for filename in ${filenames}
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef STACK_SIZE
|
#ifndef STACK_SIZE
|
||||||
#define STACK_SIZE 1024
|
#define STACK_SIZE 4 * 1024
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Variables used to clean up everything at the end of the processus
|
// Variables used to clean up everything at the end of the processus
|
||||||
@ -73,6 +73,11 @@ int thread_yield(void)
|
|||||||
if (TAILQ_EMPTY(&scheduler_fifo))
|
if (TAILQ_EMPTY(&scheduler_fifo))
|
||||||
return 0;
|
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 (HAS_STATUS(running, MUTEX_LOCKING)) {
|
||||||
if (running->mutex_prio > 0) {
|
if (running->mutex_prio > 0) {
|
||||||
running->mutex_prio--;
|
running->mutex_prio--;
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
#include "ufd.h"
|
#include "ufd.h"
|
||||||
|
#include "debug.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
#include <stdio.h>
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
|
||||||
|
|
||||||
void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread)
|
inline void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread)
|
||||||
{
|
{
|
||||||
|
TAILQ_INIT(&ufd->children);
|
||||||
ufd->thread = thread;
|
ufd->thread = thread;
|
||||||
ufd->repr = ufd,
|
ufd->repr = ufd,
|
||||||
ufd->parent = NULL;
|
ufd->parent = NULL;
|
||||||
@ -12,35 +15,48 @@ void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ufd__join(struct ufd_t* th1, struct ufd_t* th2)
|
inline void ufd__join(struct ufd_t* th1, struct ufd_t* th2)
|
||||||
{
|
{
|
||||||
struct ufd_t* a = ufd__find(th1);
|
struct ufd_t* a = ufd__find(th1);
|
||||||
struct ufd_t* b = ufd__find(th2);
|
struct ufd_t* b = ufd__find(th2);
|
||||||
|
|
||||||
if (a != b)
|
if (a != b)
|
||||||
{
|
{
|
||||||
a->parent = th2;
|
th1->parent = th2;
|
||||||
a->repr = b;
|
th1->repr = b;
|
||||||
|
th2->child = th1;
|
||||||
|
if (th1 != b)
|
||||||
|
TAILQ_INSERT_TAIL(&b->children, th1, link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct ufd_t* ufd__find(struct ufd_t* th)
|
inline struct ufd_t* ufd__find(struct ufd_t* th)
|
||||||
{
|
{
|
||||||
if (th->repr == th)
|
if (th->repr == th)
|
||||||
return th;
|
return th;
|
||||||
|
|
||||||
struct ufd_t* nrepr = ufd__find(th->repr);
|
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;
|
th->repr = nrepr;
|
||||||
return nrepr;
|
return nrepr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ufd__delete(struct ufd_t* th)
|
inline void ufd__delete(struct ufd_t* th)
|
||||||
{
|
{
|
||||||
if (th->child != NULL)
|
struct ufd_t* child;
|
||||||
|
|
||||||
|
while (!TAILQ_EMPTY(&th->children))
|
||||||
{
|
{
|
||||||
th->child->parent = th->child;
|
child = TAILQ_FIRST(&th->children);
|
||||||
th->child->repr = th->child;
|
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);
|
||||||
}
|
}
|
||||||
|
DBG("prefix %d", a);
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,21 @@
|
|||||||
#define _UNION_FIND_H_
|
#define _UNION_FIND_H_
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
|
||||||
|
TAILQ_HEAD(ufd_children_t, ufd_t);
|
||||||
|
|
||||||
// union find delete data structure
|
// union find delete data structure
|
||||||
struct ufd_t {
|
struct ufd_t {
|
||||||
struct ufd_t* parent;
|
struct ufd_t* parent;
|
||||||
struct ufd_t* repr;
|
struct ufd_t* repr;
|
||||||
struct ufd_t* child;
|
struct ufd_t* child;
|
||||||
struct context_entry_t* thread;
|
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);
|
void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
44
tst/13-join-switch.c
Normal file
44
tst/13-join-switch.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#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,7 +7,8 @@
|
|||||||
|
|
||||||
/* test de plein de switch pendant que N-1 threads sont bloqués dans join
|
/* 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 threads et de yields donnés en argument
|
* La durée du programme doit etre proportionnelle au nombre de yields
|
||||||
|
* mais ne pas varier avec le nombre de threads donné en argument.
|
||||||
*
|
*
|
||||||
* support nécessaire:
|
* support nécessaire:
|
||||||
* - thread_create()
|
* - thread_create()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user