source: CIVL/text/include/pthread.cvl@ 67577e8

1.23 2.0 main test-branch
Last change on this file since 67577e8 was b0dfafb, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

added pthread_pool_t to keep track of threads being created, which is needed by pthread_exit().

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1105 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 4.8 KB
Line 
1//Mutex types
2enum{
3PTHREAD_MUTEX_NORMAL,
4PTHREAD_MUTEX_RECURSIVE,
5PTHREAD_MUTEX_ERRORCHECK
6};
7
8enum{
9PTHREAD_MUTEX_STALLED,
10PTHREAD_MUTEX_ROBUST
11};
12
13enum{
14PTHREAD_CREATE_DETACHED,
15PTHREAD_CREATE_JOINABLE
16};
17
18enum{
19PTHREAD_SCOPE_SYSTEM,
20PTHREAD_SCOPE_PROCESS
21};
22
23enum{
24PTHREAD_INHERIT_SCHED,
25PTHREAD_EXPLICIT_SCHED
26};
27
28//Mutex initializer
29#define __LOCK_INITIALIZER 0
30#define PTHREAD_MUTEX_INITIALIZER {0,0,0,PTHREAD_MUTEX_NORMAL,__LOCK_INITIALIZER}
31#define PTHREAD_COND_INITIALIZER {__LOCK_INITIALIZER,0}
32
33//Error definitions
34enum{
35EINVAL, //Designates an invalid value
36ENOTSUP,
37EOWNERDEAD, //Designates the termination of the owning thread
38EBUSY, //Mutex is already locked
39EDEADLK, //If mutex type is errorcheck and already owns the mutex
40EPERM //If mutex is robust or errorcheck and does not own the mutex
41};
42
43/* Struct definitions */
44
45/* pthread_attr_t struct definition
46 Description: This struct corresponds to the pthread_attr_t which is the attribute of a pthread_t. It's fields
47 define the way the pthread_t is able to interact (join/detach), (memory capacity), (scope) etc.
48
49 Fields: void * stackaddr: The address of the attr's stack in memory
50 size_t stacksize: The memory capacity for the attr's stack
51 size_t guardsize: The guardsize attribute controls the size of the guard area for the created thread' stack. The
52 guardsize attribute provides protection against overflow of the stack pointer.
53 int detachstate: Defines a threads ability to join with two values: PTHREAD_CREATE_DETACHED and PTHREAD_CREATE_JOINABLE
54 int inheritsched: The inheritance scheduling policy of the thread
55 int contentionscope: Defines the contention scope of the thread
56 int schedpolicy: Determines the scheduling policy of the thread
57
58*/
59
60typedef struct {
61 void *stackaddr;
62 size_t stacksize;
63 size_t guardsize;
64 int detachstate;
65 int inheritsched;
66 int contentionscope;
67 int schedpolicy;
68} pthread_attr_t;
69
70/* pthread_mutexattr_t struct definition
71 Description: The pthread_mutexattr_t defines multiple attributes of a mutex and controls its interactions with threads
72 Fields: robust: defines the robustness of the mutex; if robust and the owning thread terminates, it will notify the
73 next thread of this to prevent deadlocks and other errors
74 pshared: defines the process shared element of the thread and which processes can interact with the mutex
75 protocol: defines the priority protocol of the mutex and which threads may interact first
76 type: defines the type of the mutex as either PTHREAD_MUTEX_DEFAULT/NORMAL, PTHREAD_MUTEX_ERRORCHECK, or
77 PTHREAD_MUTEX_RECURSIVE, each explained in pthread_mutex_lock below
78 prioceiling: defines the lowest priority the mutex's critical section can be at
79*/
80
81typedef struct {
82 int robust;
83 int pshared;
84 int protocol;
85 int type;
86 int prioceiling;
87}pthread_mutexattr_t;
88
89/* pthread_mutex_t struct definition
90 Description: The pthread_mutex_t is a locking mechanism for threads to interact with in order to control the scheduling
91 of the threads. It can be locked, which allows for blocking of other threads waiting on the mutex and unlocked, allowing
92 access. It has a pthread_mutexattr_t which defines its behavior.
93 Fields: count - used for recursive mutex, incremented when locked, decremented when unlocked, mutex released when count is 0
94 owner - current process owner of the mutex
95 lock - int of 0 or 1, respectively 0 if unlocked, 1 if locked
96 prioceiling - allows locking without adherence to the priority ceiling
97 attr - see above
98*/
99
100typedef struct {
101 int count;
102 $proc owner;
103 int lock;
104 int prioceiling;
105 pthread_mutexattr_t *attr;
106} pthread_mutex_t;
107
108//Unimplemented
109/*
110typedef struct {
111 int pshared;
112 clockid_t clock_id;
113}pthread_condattr_t;
114*/
115
116/* pthread_cond_t struct definition
117 Description: The pthread_cond_t is another locking mechanism which interacts with the mutex variable. When
118 the mutex is locked, the condition can be accessed, leading the accessing thread to unlock it, and sleep
119 until the signal is given
120 Fields: proccount - specifies the number of processes/threads still waiting on this condition variable
121 signal - Boolean value stating whether the condition is satisfied (indicated by 1) or not (0)
122*/
123
124typedef struct {
125 int proccount;
126 _Bool signal;
127} pthread_cond_t;
128
129/* pthread_t struct definition
130 Description: The pthread_t is a struct containing a $proc variable as well as a thread attribute which defines
131 its interactions with other threads. It encapsulates the $proc and allows attributes to apply to it.
132 Fields: thr: the $proc variable that is the heart of the thread
133 attr: see above
134*/
135
136typedef struct {
137 $proc thr;
138 const pthread_attr_t *attr;
139} pthread_t;
140
141typedef struct __pthread_pool_t {
142 pthread_t** threads;
143 int len;
144} __pthread_pool_t;
Note: See TracBrowser for help on using the repository browser.