+ createModelIfNotExist();
+ ModelExecution *execution = model->get_execution();
+ cdsc::snapmutex *m = execution->getMutexMap()->get(p_mutex);
+ return m->try_lock() ? 0 : EBUSY;
+}
+int pthread_mutex_unlock(pthread_mutex_t *p_mutex) {
+ ModelExecution *execution = model->get_execution();
+ cdsc::snapmutex *m = execution->getMutexMap()->get(p_mutex);
+
+ if (m != NULL) {
+ m->unlock();
+ } else {
+ printf("try to unlock an untracked pthread_mutex\n");
+ return 1;
+ }
+
+ return 0;
+}
+
+int pthread_mutex_timedlock (pthread_mutex_t *__restrict p_mutex,
+ const struct timespec *__restrict abstime) {
+// timedlock just gives the option of giving up the lock, so return and let the scheduler decide which thread goes next
+ createModelIfNotExist();
+ ModelExecution *execution = model->get_execution();
+
+ /* to protect the case where PTHREAD_MUTEX_INITIALIZER is used
+ instead of pthread_mutex_init, or where *p_mutex is not stored
+ in the execution->mutex_map for some reason. */
+ if (!execution->getMutexMap()->contains(p_mutex)) {
+ pthread_mutex_init(p_mutex, NULL);
+ }
+
+ cdsc::snapmutex *m = execution->getMutexMap()->get(p_mutex);
+
+ if (m != NULL) {
+ m->lock();
+ return 0;
+ }
+
+ return 1;
+}
+
+pthread_t pthread_self() {
+ createModelIfNotExist();
+ Thread* th = model->get_current_thread();
+ return (pthread_t)th->get_id();
+}
+
+int pthread_key_delete(pthread_key_t) {
+ model_print("key_delete is called\n");
+ return 0;
+}
+
+int pthread_cond_init(pthread_cond_t *p_cond, const pthread_condattr_t *attr) {
+ cdsc::snapcondition_variable *v = new cdsc::snapcondition_variable();
+
+ ModelExecution *execution = model->get_execution();
+ execution->getCondMap()->put(p_cond, v);
+ return 0;