*/
Thread * ModelAction::get_thread_operand() const
{
- if (type == THREAD_CREATE)
- /* THREAD_CREATE uses (Thread *) for location */
- return (Thread *)get_location();
- else if (type == THREAD_JOIN)
+ if (type == THREAD_CREATE) {
+ /* THREAD_CREATE stores its (Thread *) in a thrd_t::priv */
+ thrd_t *thrd = (thrd_t *)get_location();
+ return thrd->priv;
+ } else if (type == THREAD_JOIN)
/* THREAD_JOIN uses (Thread *) for location */
return (Thread *)get_location();
else
*/
int thrd_create(thrd_t *t, thrd_start_t start_routine, void *arg)
{
- Thread *thread;
- thread = new Thread(t, start_routine, arg);
- model->add_thread(thread);
+ struct thread_params params = { start_routine, arg };
/* seq_cst is just a 'don't care' parameter */
- model->switch_to_master(new ModelAction(THREAD_CREATE, std::memory_order_seq_cst, thread, VALUE_NONE));
+ model->switch_to_master(new ModelAction(THREAD_CREATE, std::memory_order_seq_cst, t, (uint64_t)¶ms));
return 0;
}
switch (curr->get_type()) {
case THREAD_CREATE: {
- Thread *th = curr->get_thread_operand();
+ thrd_t *thrd = (thrd_t *)curr->get_location();
+ struct thread_params *params = (struct thread_params *)curr->get_value();
+ Thread *th = new Thread(thrd, params->func, params->arg);
+ add_thread(th);
th->set_creation(curr);
/* Promises can be satisfied by children */
for (unsigned int i = 0; i < promises->size(); i++) {
if (model->params.fairwindow != 0 && head_idx > (int)model->params.fairwindow)
prevfairness = node_list[head_idx - model->params.fairwindow];
}
- node_list.push_back(new Node(act, head, model->get_num_threads(), prevfairness));
+
+ int next_threads = model->get_num_threads();
+ if (act->get_type() == THREAD_CREATE)
+ next_threads++;
+ node_list.push_back(new Node(act, head, next_threads, prevfairness));
total_nodes++;
head_idx++;
return NULL;
#include <threads.h>
#include "modeltypes.h"
+struct thread_params {
+ thrd_start_t func;
+ void *arg;
+};
+
/** @brief Represents the state of a user Thread */
typedef enum thread_state {
/** Thread was just created and hasn't run yet */