2 #include "threads-model.h"
7 /* global "model" object */
11 int pthread_create(pthread_t *t, const pthread_attr_t * attr,
12 pthread_start_t start_routine, void * arg) {
13 struct pthread_params params = { start_routine, arg };
15 ModelAction *act = new ModelAction(PTHREAD_CREATE, std::memory_order_seq_cst, t, (uint64_t)¶ms);
17 /* seq_cst is just a 'don't care' parameter */
18 model->switch_to_master(act);
23 int pthread_join(pthread_t t, void **value_ptr) {
24 // Thread *th = model->get_pthread(t);
25 ModelExecution *execution = model->get_execution();
26 Thread *th = execution->get_pthread(t);
28 model->switch_to_master(new ModelAction(PTHREAD_JOIN, std::memory_order_seq_cst, th, id_to_int(th->get_id())));
32 void *rtval = th->get_pthread_return();
38 void pthread_exit(void *value_ptr) {
39 Thread * th = thread_current();
40 model->switch_to_master(new ModelAction(THREAD_FINISH, std::memory_order_seq_cst, th));
43 int pthread_mutex_init(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *) {
44 std::mutex *m = new std::mutex();
46 ModelExecution *execution = model->get_execution();
47 execution->mutex_map.put(p_mutex, m);
51 int pthread_mutex_lock(pthread_mutex_t *p_mutex) {
52 ModelExecution *execution = model->get_execution();
53 std::mutex *m = execution->mutex_map.get(p_mutex);
58 int pthread_mutex_trylock(pthread_mutex_t *p_mutex) {
59 ModelExecution *execution = model->get_execution();
60 std::mutex *m = execution->mutex_map.get(p_mutex);
65 int pthread_mutex_unlock(pthread_mutex_t *p_mutex) {
66 ModelExecution *execution = model->get_execution();
67 std::mutex *m = execution->mutex_map.get(p_mutex);
73 pthread_t pthread_self() {
74 Thread* th = model->get_current_thread();
78 int pthread_key_delete(pthread_key_t) {
79 model_print("key_delete is called\n");