Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Electrostat-Lab/CThreads
Testcases about POSIX Threads --Unix-based & Linux Systems
https://github.com/Electrostat-Lab/CThreads
c ccoffee cpp gcc-complier posix-threads shell unix
Last synced: 23 days ago
JSON representation
Testcases about POSIX Threads --Unix-based & Linux Systems
- Host: GitHub
- URL: https://github.com/Electrostat-Lab/CThreads
- Owner: Electrostat-Lab
- Created: 2021-07-29T00:57:23.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-09T21:03:23.000Z (over 1 year ago)
- Last Synced: 2024-08-08T23:29:53.031Z (3 months ago)
- Topics: c, ccoffee, cpp, gcc-complier, posix-threads, shell, unix
- Language: C++
- Homepage:
- Size: 70.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CThreads
## Let's dive into CThreads Interface aka `POSIX Threads` which isn't shipped natively with C, it's based on Unix :
https://www.ibm.com/docs/en/zos/2.4.0?topic=files-pthreadh-thread-interfaces### Resources for POSIX Threads of Unix :
https://www.ibm.com/docs/en/i/7.1?topic=ssw_ibm_i_71/apis/concept8.htm
https://www.geeksforgeeks.org/thread-functions-in-c-c/### Mutex -- Mutually Exclusive -- Synchronized -- Object :
https://www.ibm.com/docs/en/zos/2.3.0?topic=functions-pthread-mutex-init-initialize-mutex-object### struct timespec --used by the Mutex System of `pthread.h` in C method :
```c
#include
/* Wait until lock becomes available, or specified time passes. */
extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
const struct timespec *__restrict__abstime);
```
#### struct timespec -- source from GNU :
```c
/* NB: Include guard matches what uses. */
#ifndef _STRUCT_TIMESPEC
#define _STRUCT_TIMESPEC 1#include
#include/* POSIX.1b structure for a time value. This is like a `struct timeval' but
has nanoseconds instead of microseconds. */
struct timespec
{
__time_t tv_sec; /* Seconds. */
#if __WORDSIZE == 64 \
|| (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64) \
|| __TIMESIZE == 32
__syscall_slong_t tv_nsec; /* Nanoseconds. */
#else
# if __BYTE_ORDER == __BIG_ENDIAN
int: 32; /* Padding. */
long int tv_nsec; /* Nanoseconds. */
# else
long int tv_nsec; /* Nanoseconds. */
int: 32; /* Padding. */
# endif
#endif
};#endif
```
https://en.cppreference.com/w/c/chrono/timespec# To Build, use shell command/terminal :
```bash
┌─[twisted@parrot]─[~/GradleProjects/CThreads/build]
└──╼ $./compile.sh
Compiling the project
Successfully Compiled
```
# To run :```bash
┌─[twisted@parrot]─[~/GradleProjects/CThreads/output]
└──╼ $./ThreadsTest.exec
Main Thread joined
Async 2 joined
139843706689280 Aysnc 2 Terminated
Thread 1
Async 1 joined
139843715081984 Aysnc 1 Terminated
139843698296576 (Thread 1) has been detached & terminated
Thread 2
139843698296576 (Thread 2) has been detached & terminated
mutex_initialized & property settled to NORMAL single lock mutually events
mutex object obtained by Event 1 -- Event 1 execution starts
mutex_locked to this Event 1, concurrent threads will wait until unlock occurs
mutex object obtained by Event 2 -- Event 2 execution starts
mutex_locked to this Event 2, concurrent threads will wait until unlock occurs
```### Tips : You can open the code on vscode, use c++ code completion, syntax highlighting.