{"id":21429582,"url":"https://github.com/mayank-02/multithreading-library","last_synced_at":"2025-07-14T11:30:42.414Z","repository":{"id":188402708,"uuid":"246230614","full_name":"mayank-02/multithreading-library","owner":"mayank-02","description":"A lightweight C library based on one-one and many-one model for threading.","archived":false,"fork":false,"pushed_at":"2023-10-02T16:46:49.000Z","size":680,"stargazers_count":18,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-10-02T22:40:12.195Z","etag":null,"topics":["c","conditional-variables","many-to-one","multithreading","mutex","one-to-one","semaphore","spinlock","synchronization"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mayank-02.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-03-10T07:04:22.000Z","updated_at":"2023-10-02T16:46:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"d702a238-f351-402f-aaff-7a7b094da1d4","html_url":"https://github.com/mayank-02/multithreading-library","commit_stats":null,"previous_names":["mayank-02/multithreading-library"],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayank-02%2Fmultithreading-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayank-02%2Fmultithreading-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayank-02%2Fmultithreading-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayank-02%2Fmultithreading-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mayank-02","download_url":"https://codeload.github.com/mayank-02/multithreading-library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225971249,"owners_count":17553461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","conditional-variables","many-to-one","multithreading","mutex","one-to-one","semaphore","spinlock","synchronization"],"created_at":"2024-11-22T22:18:22.846Z","updated_at":"2024-11-22T22:18:23.360Z","avatar_url":"https://github.com/mayank-02.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg width=20%  src=\"./doc/logo.png\"\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cimg width=25% src=\"./doc/logo-mthread.png\"\u003e\u003c/p\u003e\n\n[![GitHub issues](https://img.shields.io/github/issues/mayank-02/multithreading-library)](https://github.com/mayank-02/multithreading-library)\n![Contributions welcome](https://img.shields.io/badge/contributions-welcome-green.svg)\n[![License](https://img.shields.io/github/license/mayank-02/multithreading-library)](https://opensource.org/licenses/GPL-3.0)\n\nA lightweight C library based on one-one and many-one model for threading.\n\n## Contents\n\n+ [Building](#building)\n+ [Using mthread in your project](#using-mthread-in-your-project)\n+ [Usage and examples](#usage-and-examples)\n+ [API documentation](#api-documentation)\n+ [Running tests](#running-tests)\n+ [Time and space complexity](#time-and-space-complexity)\n+ [Development and contributing](#development-and-contributing)\n+ [Acknowledgements](#acknowledgements)\n\n## Building\n\nmthread uses make to build libraries (static and shared) and binaries (for tests).\nExecute following commands to build mthread using make:\n\n``` bash\nmake\n```\n\nThis will create binaries in `bin/` directory and libraries (static and shared) in the current directory.\n\nOptionally, you can run `sudo make install` to install mthread library on your machine (on Linux, this will usually install it to `usr/local/lib` and `usr/local/include`).\n\n## Using mthread in your project\n\nYou can use mthread in you project by either directly copying header and source files from [one-one/](one-one/), or by linking mthread library (see [Building](#building) for instructions how to build mthread libraries).\nIn any case, only thing that you have to do in your source files is to include `mthread.h`.\n\nTo get you started quickly, let's take a look at a few ways to get a simple Hello World project working.\n\nOur Hello World project has just one source file, `example.c` file, and it looks like this:\n\n```c\n#include \u003cstdio.h\u003e\n#include \"mthread.h\"\n\nvoid worker(void) {\n    printf(\"Hello World!\\n\");\n    mthread_exit(NULL);\n}\n\nint main() {\n    mthread_t tid;\n    mthread_init();\n    mthread_create(\u0026tid, NULL, worker, NULL);\n    mthread_join(tid, NULL);\n    return 0;\n}\n```\n\n### Approach #1: Copying mthread header file and static library\n\nInstead of copying mthread source files, you could copy the static library or a shared object (check [Building](#building) on how to create static library / shared object). We also need to copy mthread header files. We get following project structure:\nIn case of a static library:\n\n```\nexample.c       -\u003e your program\nmthread.h       -\u003e copied from mthread\nlibmthread.a    -\u003e copied from mthread\n```\n\nIn case of shared object:\n\n```\nexample.c       -\u003e your program\nmthread.h       -\u003e copied from mthread\nlibmthread.so   -\u003e copied from mthread\n```\n\nNow you can compile it with\n\n```bash\ngcc example.c -o example -L. -llibmthread.\n```\n\n### Approach #2: Install mthread library on machine (TODO)\n\nAlternatively, you could avoid copying any mthread files and instead install libraries by running `sudo make install` (check [Building](#building)). Now, all you have to do to compile your project is `gcc example.c -o example -llibmthread`.\nIf you get error message like `cannot open shared object file: No such file or directory`, make sure that your linker includes path where mthread was installed.\n\n## Usage and examples\n\nTo know more about how to use mthread library, check out the various tests written in the `test` directory of each model.\n\n## API documentation\n\n+ Types are named **mthread\\_[type]\\_t** (examples: mthread_t, mthread_cond_t, etc.)\n\n+ Functions are called **mthread\\_[type]\\_[action]** with a few exceptions that are mthread_[action] and pertain to the API in whole and not a specific type.\n+ Constants are named **MTHREAD\\_[NAME]**\n\nThe mthreads API is inherently simple. Not in the sense that it makes multi-threaded (MT) programming a breeze (I doubt this is possible), but in the sense that it provides everything that's needed to write MT programs, and only that.\n\nTo generate the latest API documentation yourself from the source, you need to have [doxygen](www.doxygen.org) installed.\nPosition yourself in the root directory of the model you are interested in.\nThen run `make docs`. This will output a `/docs/html` and `/docs/latex` folder.\nThen open `docs/html/index.html` file with your favorite browser.\n\nAlternatively, you can directly check [mthread.h](one-one/include/mthread.h) for one-one and [mthread.h](many-one/include/mthread.h) for many-one\n\n## Running tests\n\nCheck [Building](#building) to see how to build binaries.\nTo run each test, just run `./run_tests` from the root directory of both models.\nDefault values are used for tests requiring command line arguments.\n\n## Time and space complexity\n\nThe library maintains a queue for internal book keeping. Thus, the functions have different time complexities. They have a best case time complexity of `O(1)` and worst case time complexity of `O(N)`, N being the number of threads spawned. Space complexity is `O(N)`.\n\n## Implementation Details\n\n+ To know the implementation details of one-one threading model, please check out it's [README](one-one/README.md)\n\n+ To know the implementation details of many-one threading model, please check out it's [README](many-one/README.md)\n\n## Development and contributing\n\nFeel free to send pull requests and raise issues.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmayank-02%2Fmultithreading-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmayank-02%2Fmultithreading-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmayank-02%2Fmultithreading-library/lists"}