The Bthread library was created for the Interdisciplinary Project V subject of the computer science course at PUC Minas with educational purposes in mind, such as, helping students understand how concurrent programs work as well as providing ways for the developing of concurrent programming practices.
The Bthread library implements a preemptive aproach with round-robin and provides the following features: Thread creation and termination
- Thread joining and detaching
- Thread cancellation
- Thread yield
- Mutexes
The Bthread library API is composed of the following functions:
int bthread_create(bthread_t *thread, void *(*start_routine)(), void *arg);
int bthread_join(bthread_t thread, void **thread_return);
int bthread_detach(bthread_t thread);
void bthread_yield(void);
bthread_t bthread_self(void);
int bthread_cancel(bthread_t thread);
struct bt_mutex *bthread_mutex_init(void);
int bthread_mutex_lock(struct bt_mutex *mutex);
int bthread_mutex_unlock(struct bt_mutex *mutex);
int bthread_mutex_destroy(struct bt_mutex *mutex);
For more information about the Bthread library API, please refer to the bthread.h header file.
To use the Bthread library in a Nanvix program, the following steps must be taken:
- Setup the Nanvix development environment as described at setup.md.
- Create a new user program in the
src/ubin
directory. - Include the
bthread.h
header file in the user program. - Build Nanvix as described at build.md.
- Run Nanvix using your choosen system simulator (QEMU is recommended).
A simple example of the Bthread library usage is available in the user program bthd
in Nanvix,
its source code is available at src/ubin/bthd/bthd.c.
Nanvix is a Unix-like operating system written by Pedro Henrique Penna for educational purposes. It is designed to be simple and small, but also modern and fully featured.
Nanvix targets 32-bit x86-based PCs and only requires a floppy or CD-ROM drive and 16 MB of RAM. You can run it either in a real PC or in a virtual machine, using a system image.
Nanvix is a free software that is under the GPL V3 license and is maintained by Pedro Henrique Penna. Any questions or suggestions send him an email: [email protected]
BThread is also under the GPL V3 license and was made by: