| 1 | #ifndef _CIVLPTHREAD_
|
|---|
| 2 | #define _CIVLPTHREAD_
|
|---|
| 3 |
|
|---|
| 4 | #include <civlc.cvh>
|
|---|
| 5 | #pragma CIVL ACSL
|
|---|
| 6 | // types
|
|---|
| 7 |
|
|---|
| 8 | typedef struct _pthread_attr_t pthread_attr_t;
|
|---|
| 9 | typedef struct _pthread_t pthread_t;
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 | /* A global pthread pool which must only be operated by local pthread pool. */
|
|---|
| 13 | typedef struct _pthread_gpool_t * $pthread_gpool_t;
|
|---|
| 14 |
|
|---|
| 15 | /* A datatype representing a local pthread pool which is used for
|
|---|
| 16 | * operating global pthread pools. The local pthread pool type has
|
|---|
| 17 | * a handle of a global pthread pool.
|
|---|
| 18 | */
|
|---|
| 19 | typedef struct _pthread_pool_t * $pthread_pool_t;
|
|---|
| 20 |
|
|---|
| 21 | // Function Prototypes
|
|---|
| 22 | //void _pthread_exit(void *, _Bool);
|
|---|
| 23 |
|
|---|
| 24 | /* ************************** Functions of $pthread_gpool ************************** */
|
|---|
| 25 |
|
|---|
| 26 | /* Creates a new global pthread pool and returns a handle to it.
|
|---|
| 27 | * The global pthread will have an incomplete array of pthread constructs. */
|
|---|
| 28 | /*@ depends_on \nothing;
|
|---|
| 29 | @ assigns \nothing;
|
|---|
| 30 | @ reads \nothing;
|
|---|
| 31 | @*/
|
|---|
| 32 | $atomic_f $pthread_gpool_t $pthread_gpool_create($scope scope);
|
|---|
| 33 |
|
|---|
| 34 | /* De-allocation a _pthread_gpool_t object */
|
|---|
| 35 | /*@ depends_on \access(gpool);
|
|---|
| 36 | @ assigns gpool;
|
|---|
| 37 | @ reads \nothing;
|
|---|
| 38 | @*/
|
|---|
| 39 | $atomic_f void $pthread_gpool_destroy($pthread_gpool_t gpool);
|
|---|
| 40 |
|
|---|
| 41 | /*@ depends_on \access(gpool, thread);
|
|---|
| 42 | @ executes_when \true;
|
|---|
| 43 | @*/
|
|---|
| 44 | $system[pthread] void $pthread_gpool_add($pthread_gpool_t gpool, pthread_t * thread);
|
|---|
| 45 |
|
|---|
| 46 | /* Gets the size of the global thread pool */
|
|---|
| 47 | /*@ depends_on \access(gpool);
|
|---|
| 48 | @ executes_when \true;
|
|---|
| 49 | @*/
|
|---|
| 50 | $system[pthread] int $pthread_gpool_size($pthread_gpool_t gpool);
|
|---|
| 51 |
|
|---|
| 52 | /* Gets the PID of the index'th thread in the pool */
|
|---|
| 53 | /*@ depends_on \access(gpool);
|
|---|
| 54 | @ executes_when \true;
|
|---|
| 55 | @*/
|
|---|
| 56 | $system[pthread] $proc $pthread_gpool_thread($pthread_gpool_t gpool, int index);
|
|---|
| 57 |
|
|---|
| 58 | /* Waits for all threads in the pool to terminate */
|
|---|
| 59 | /*@ depends_on \access(gpool);
|
|---|
| 60 | @*/
|
|---|
| 61 | $system[pthread] void $pthread_gpool_join($pthread_gpool_t gpool);
|
|---|
| 62 |
|
|---|
| 63 | /* *************************** Functions of $pthread_pool ************************** */
|
|---|
| 64 |
|
|---|
| 65 | /* Creates a new local pthread pool object and returns a handle to it. */
|
|---|
| 66 | /*@ depends_on \nothing;
|
|---|
| 67 | @ assigns gpool;
|
|---|
| 68 | @ reads \nothing;
|
|---|
| 69 | @ executes_when \true;
|
|---|
| 70 | @*/
|
|---|
| 71 | $atomic_f $pthread_pool_t $pthread_pool_create($scope scope, $pthread_gpool_t gpool);
|
|---|
| 72 |
|
|---|
| 73 | /* Creates a new local pthread pool object for the main function, also all the main thread to the thread pool;
|
|---|
| 74 | and returns a handle to the new local pthread pool object. */
|
|---|
| 75 | /*@ depends_on \nothing;
|
|---|
| 76 | @ assigns gpool;
|
|---|
| 77 | @ reads \nothing;
|
|---|
| 78 | @ executes_when \true;
|
|---|
| 79 | @*/
|
|---|
| 80 | $atomic_f $pthread_pool_t $pthread_pool_create_main($scope scope, $pthread_gpool_t gpool);
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 | /* Terminates this thread */
|
|---|
| 84 | /*@ depends_on \access(pool, value);
|
|---|
| 85 | @ executes_when \true;
|
|---|
| 86 | @*/
|
|---|
| 87 | $atomic_f void $pthread_pool_terminates($pthread_pool_t pool, void* value);
|
|---|
| 88 |
|
|---|
| 89 | /*@ depends_on \access(pool);
|
|---|
| 90 | @ executes_when \true;
|
|---|
| 91 | @*/
|
|---|
| 92 | $system[pthread] _Bool $pthread_pool_get_terminated($pthread_pool_t pool);
|
|---|
| 93 |
|
|---|
| 94 | /*@ depends_on \access(pool);
|
|---|
| 95 | @ executes_when \true;
|
|---|
| 96 | @*/
|
|---|
| 97 | $atomic_f _Bool $pthread_pool_is_terminated($pthread_pool_t pool, $proc pid);
|
|---|
| 98 |
|
|---|
| 99 | /* De-allocation a _pthread_gpool_t object */
|
|---|
| 100 | /*@ depends_on \access(pool);
|
|---|
| 101 | @ assigns pool;
|
|---|
| 102 | @ reads \nothing;
|
|---|
| 103 | @*/
|
|---|
| 104 | $atomic_f void $pthread_pool_destroy($pthread_pool_t pool);
|
|---|
| 105 |
|
|---|
| 106 | /*@ depends_on \access(pool);
|
|---|
| 107 | @ executes_when \true;
|
|---|
| 108 | @*/
|
|---|
| 109 | $system[pthread] pthread_t $pthread_pool_thread($pthread_pool_t pool);
|
|---|
| 110 |
|
|---|
| 111 | /**
|
|---|
| 112 | * Causes current thread to immediately terminate; if currently in the main method as specified by the
|
|---|
| 113 | * isMain parameter, the main method will wait for each thread to terminate before it terminates. The value
|
|---|
| 114 | * value_ptr will be made accessible in the location stated in pthread_join
|
|---|
| 115 | * Corresponding specification: p. 1655-6
|
|---|
| 116 | *
|
|---|
| 117 | * @param *value_ptr
|
|---|
| 118 | * The value to be stored in the location stated by pthread_join
|
|---|
| 119 | * @param isMain
|
|---|
| 120 | * Is this thread the main thread?
|
|---|
| 121 | * @param *arr
|
|---|
| 122 | * The array of threads which need to be waited upon by the main thread
|
|---|
| 123 | * @param len
|
|---|
| 124 | * The length of the array of threads to be waited upon
|
|---|
| 125 | * @return Returns 0 upon successful completion
|
|---|
| 126 | */
|
|---|
| 127 | /*@ depends_on \access(value_ptr, pool);
|
|---|
| 128 | @ executes_when \true;
|
|---|
| 129 | @*/
|
|---|
| 130 | $atomic_f void $pthread_exit(void *value_ptr, $pthread_pool_t pool);
|
|---|
| 131 |
|
|---|
| 132 | #endif
|
|---|