{"id":13339652,"url":"https://github.com/Electrostat-Lab/CThreads","last_synced_at":"2025-03-11T14:32:07.062Z","repository":{"id":48363620,"uuid":"390554315","full_name":"Electrostat-Lab/CThreads","owner":"Electrostat-Lab","description":"Testcases about POSIX Threads --Unix-based \u0026 Linux Systems","archived":false,"fork":false,"pushed_at":"2023-03-09T21:03:23.000Z","size":72,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-06T23:30:40.822Z","etag":null,"topics":["c","ccoffee","cpp","gcc-complier","posix-threads","shell","unix"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Electrostat-Lab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-29T00:57:23.000Z","updated_at":"2022-09-20T01:50:59.000Z","dependencies_parsed_at":"2024-10-23T23:03:04.228Z","dependency_job_id":"e322d01b-c863-4dda-9c38-a077b8957b5b","html_url":"https://github.com/Electrostat-Lab/CThreads","commit_stats":null,"previous_names":["electrostat-lab/cthreads"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Electrostat-Lab%2FCThreads","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Electrostat-Lab%2FCThreads/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Electrostat-Lab%2FCThreads/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Electrostat-Lab%2FCThreads/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Electrostat-Lab","download_url":"https://codeload.github.com/Electrostat-Lab/CThreads/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243051993,"owners_count":20228308,"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","ccoffee","cpp","gcc-complier","posix-threads","shell","unix"],"created_at":"2024-07-29T19:21:07.971Z","updated_at":"2025-03-11T14:32:06.757Z","avatar_url":"https://github.com/Electrostat-Lab.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CThreads\n\n## Let's dive into CThreads Interface aka `POSIX Threads` which isn't shipped natively with C, it's based on Unix :\nhttps://www.ibm.com/docs/en/zos/2.4.0?topic=files-pthreadh-thread-interfaces\n\n### Resources for POSIX Threads of Unix :\nhttps://www.ibm.com/docs/en/i/7.1?topic=ssw_ibm_i_71/apis/concept8.htm\n\u003cbr/\u003e\nhttps://www.geeksforgeeks.org/thread-functions-in-c-c/\n\n### Mutex -- Mutually Exclusive -- Synchronized -- Object :\nhttps://www.ibm.com/docs/en/zos/2.3.0?topic=functions-pthread-mutex-init-initialize-mutex-object\n\n### struct timespec --used by the Mutex System of `pthread.h` in C method :\n```c\n#include \u003cbits/types/struct_timespec.h\u003e\n/* Wait until lock becomes available, or specified time passes. */\nextern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,\n\t\t\t\t    const struct timespec *__restrict__abstime);\n``` \n#### struct timespec -- source from GNU : \n```c\n/* NB: Include guard matches what \u003clinux/time.h\u003e uses.  */\n#ifndef _STRUCT_TIMESPEC\n#define _STRUCT_TIMESPEC 1\n\n#include \u003cbits/types.h\u003e\n#include \u003cbits/endian.h\u003e\n\n/* POSIX.1b structure for a time value.  This is like a `struct timeval' but\n   has nanoseconds instead of microseconds.  */\nstruct timespec\n{\n  __time_t tv_sec;\t\t/* Seconds.  */\n#if __WORDSIZE == 64 \\\n  || (defined __SYSCALL_WORDSIZE \u0026\u0026 __SYSCALL_WORDSIZE == 64) \\\n  || __TIMESIZE == 32\n  __syscall_slong_t tv_nsec;\t/* Nanoseconds.  */\n#else\n# if __BYTE_ORDER == __BIG_ENDIAN\n  int: 32;           /* Padding.  */\n  long int tv_nsec;  /* Nanoseconds.  */\n# else\n  long int tv_nsec;  /* Nanoseconds.  */\n  int: 32;           /* Padding.  */\n# endif\n#endif\n};\n\n#endif\n```\nhttps://en.cppreference.com/w/c/chrono/timespec\n\n\n# To Build, use shell command/terminal : \n\n```bash\n┌─[twisted@parrot]─[~/GradleProjects/CThreads/build]\n└──╼ $./compile.sh \nCompiling the project\nSuccessfully Compiled\n```\n# To run :\n\n```bash\n┌─[twisted@parrot]─[~/GradleProjects/CThreads/output]\n└──╼ $./ThreadsTest.exec\nMain Thread joined\nAsync 2 joined\n139843706689280 Aysnc 2 Terminated\nThread 1\nAsync 1 joined\n139843715081984 Aysnc 1 Terminated\n139843698296576 (Thread 1) has been detached \u0026 terminated\nThread 2\n139843698296576 (Thread 2) has been detached \u0026 terminated\nmutex_initialized \u0026 property settled to NORMAL single lock mutually events\nmutex object obtained by Event 1 -- Event 1 execution starts\nmutex_locked to this Event 1, concurrent threads will wait until unlock occurs\nmutex object obtained by Event 2 -- Event 2 execution starts\nmutex_locked to this Event 2, concurrent threads will wait until unlock occurs\n```\n\n### Tips : You can open the code on vscode, use c++ code completion, syntax highlighting.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FElectrostat-Lab%2FCThreads","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FElectrostat-Lab%2FCThreads","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FElectrostat-Lab%2FCThreads/lists"}