Example #1
0
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                   void *(*start_routine)(void*), void *arg)
{
    init();
    printf("Thread Creation no %d \n",THREAD_COUNT);
    THREAD_COUNT++;

    struct Thread_Arg th_arg;

    th_arg.start_routine=start_routine;
    th_arg.arg=arg;

    int ret = original_pthread_create(thread, attr, closure_wrapper, (void*)&th_arg);

    struct thread_data* new_thread = MALLOC(struct thread_data);
    new_thread->thread_id=*thread;
    new_thread->local_thread_id=THREAD_COUNT;
    new_thread->state=PTHREAD_ACTIVE_THREAD;

    all_thread.put(*thread,new_thread);

    //Set next thread to newly created thread
    //Execute newly created thread instantenously

    next_thread=*thread;

    sched();

    // TODO
    return ret;
}
Example #2
0
int pthread_mutex_lock(pthread_mutex_t *mutex) {
    //    init();
    //This is a non deterministic point . Capture non-determinism here
    findnextthreadtoschedule(NULL);

    // Call scheduler and wait for your turn
    sched();

    //I am not worthy of this lock
    while(!mutex_lock_validity(mutex)) {
        findnextthreadtoschedule(pthread_self());
        sched();
    }

    logChoice(all_thread.indexnum(pthread_self()),getActiveThreadNum());
    incrementLevel();

    PRINT("ACQUIRING LOCK %lx \n",mutex);
    lock_map.put(mutex,(pthread_self()));
    return original_pthread_mutex_lock(mutex);
    // TODO
}
Example #3
0
void
init(void) {
    if(!initialized) {
        initTracer();
        original_pthread_create=( int(*)(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*) )dlsym(RTLD_NEXT,"pthread_create");
        original_pthread_mutex_lock =(int (*)(pthread_mutex_t*))dlsym(RTLD_NEXT, "pthread_mutex_lock");
        original_pthread_mutex_unlock =(int (*)(pthread_mutex_t*))dlsym(RTLD_NEXT, "pthread_mutex_unlock");
        original_pthread_join = (int (*)(pthread_t, void**))dlsym(RTLD_NEXT, "pthread_join");
        initialized=true;

        THREAD_COUNT++;

        //insert main thread in the list
        struct thread_data* main_thread=MALLOC(struct thread_data);
        main_thread->thread_id=pthread_self();
        main_thread->state=PTHREAD_ACTIVE_THREAD;
        main_thread->local_thread_id=THREAD_COUNT;

        all_thread.comparator=pthread_equal;
        all_thread.put(pthread_self(),main_thread);

        original_pthread_mutex_lock(&SCHED_LOCK);
    }
Example #4
0
    void run(std::istream& in)
    	    {
    	    vector<string> tokens;
    	    string line;
    	    int chromCol=0;
    	    int posCol=1;
    	    int idCol=2;
    	    int refCol=3;
    	    int altCol=4;
    	    int sampleCol=-1;

    	    while(getline(in,line,'\n'))
    		    {
    		    if(AbstractApplication::stopping()) break;
    		    if(line.empty() || line[0]=='#') continue;
    		    tokenizer.split(line,tokens);

    		    string chrom=tokens[chromCol];
    		    chat *p2;
    		    int pos=(int)strtol(tokens[posCol].c_str(),&p2,10);
    		    string id=tokens[idCol];
    		    string ref=tokens[refCol];
    		    string alt=tokens[altCol];
    		    string sampleName=tokens[sampleCol];
    		    Row* therow=NULL;
    		    if(!rows.empty() &&
    			rows.back()->pos->chrom.compare(chrom)==0 &&
    			rows.back()->pos->pos==pos &&
    			rows.back()->ref.compare(ref)==0 &&
    			rows.back()->alt.compare(alt)==0
    			)
    			{
    			therow=rows.back();
    			}
    		    else
    			{
    			therow=new Row;
    			therow->pos=new ChromPosition(chrom,pos);
    			therow->id.assign(id);
    			therow->ref.assign(ref);
    			therow->alt.assign(alt);
    			rows.push_back(therow);
    			}
    		    int index_sample=0;
    		    if(sampleCol==-1)
    			{
    			if(sample2col.empty())
    			    {
    			    Sample* sample=new Sample;
    			    sample->name.assign("Sample");
    			    sample->column_index=0;
    			    samples.push_back(sample);
    			    }
    			index_sample=0;
    			}
    		    else
    			{
			map<string,Sample*>::iterator r= sample2col.find(sampleName);
			if(r==sample2col.end())
			    {
			    Sample* sample=new Sample;
			    sample->name.assign(sampleName);
			    sample->column_index=sample2col.size();
			    index_sample=sample->column_index;
			    samples.push_back(sample);
			    sample2col.put(sample->name,sample);
			    }
			else
			    {
			    index_sample=r->second->column_index;
			    }
    			}

    		    if(index_sample>=therow->data.size())
    			{
    			therow->data.resize(index_sample+1);
    			}
    		    Data* data=new Data;
    		    therow->data.assign(index_sample,data);
    		    }
    	    }