VM::VM(uint32_t id, SharedState& shared) : ManagedThread(id, shared, ManagedThread::eRuby) , saved_call_frame_(0) , stack_start_(0) , run_signals_(false) , thread_step_(false) , shared(shared) , waiting_channel_(this, (Channel*)Qnil) , interrupted_exception_(this, (Exception*)Qnil) , interrupt_with_signal_(false) , waiting_header_(0) , custom_wakeup_(0) , custom_wakeup_data_(0) , om(shared.om) , check_local_interrupts(false) , thread_state_(this) , thread(this, nil<Thread>()) , current_fiber(this, nil<Fiber>()) , root_fiber(this, nil<Fiber>()) { set_stack_size(cStackDepthMax); if(shared.om) { young_start_ = shared.om->young_start(); young_end_ = shared.om->yound_end(); local_slab_.refill(0, 0); } tooling_env_ = rbxti::create_env(this); tooling_ = false; allocation_tracking_ = shared.config.allocation_tracking; }
VM::VM(SharedState& shared) : ManagedThread(shared, ManagedThread::eRuby) , saved_call_frame_(0) , stack_start_(0) , run_signals_(false) , thread_step_(false) , shared(shared) , waiter_(NULL) , interrupt_with_signal_(false) , om(shared.om) , interrupts(shared.interrupts) , check_local_interrupts(false) , thread_state_(this) , thread(this, nil<Thread>()) , current_fiber(this, nil<Fiber>()) , root_fiber(this, nil<Fiber>()) { set_stack_size(cStackDepthMax); os_thread_ = pthread_self(); // initial value if(shared.om) { young_start_ = shared.om->young_start(); young_end_ = shared.om->yound_end(); shared.om->refill_slab(local_slab_); } tooling_env_ = rbxti::create_env(this); tooling_ = false; }
int main( int argc, char **argv ) { pthread_attr_t attr; size_t stacksize; struct thread_info threads[NTHREADS]; int thread_num; unsigned long start = memory_report(); printf( "Create %d threads with stack size = %d\n", NTHREADS, KB(set_stack_size(&attr)) ); for ( thread_num = 0 ; thread_num < NTHREADS ; thread_num++ ) { struct thread_info *current = &( threads[thread_num] ); if ( pthread_create(&(current->tid), &attr, dowork, current) != 0 ) { perror( "pthread_create" ); exit( -1 ); } pthread_yield(); /* to make sure thread gets started */ } unsigned long end = memory_report(); unsigned long delta = end - start; printf( "Memory delta is %lu KB (%lu MB)\n", KB(delta), KB(KB(delta)) ); pthread_exit(NULL); }
// pop the first lnode in the stack // decrement the size of stack // if the stack is empty, return NULL; // lnode *pop(lnode *head) { lnode *node = head->next; if (node != NULL) { // there is something in the stack head->next = node->next; node->next = NULL; set_stack_size(head, stack_size(head)-1); } return node; }
// empty out the stack (except the dummy) // void stack_flush(lnode *head) { lnode *curr = head->next; while (curr != NULL) { lnode *tmp = curr->next; node_destruct(curr); curr = tmp; } head->next = NULL; set_stack_size(head, 0); }
matrix_mul::matrix_mul(sc_core::sc_module_name name, double period, sc_core::sc_time_unit unit, unsigned char id, unsigned char priority, bool verbose) : SpaceBaseModule(name, period, unit, id, priority, verbose) { SC_THREAD(thread); set_stack_size(0x16000 + 100 * 100 * 4 * 3); m_result = new unsigned int[100 * 100]; m_operand1 = new unsigned int[100 * 100]; m_operand2 = new unsigned int[100 * 100]; }
VM::VM(SharedState& shared) : ManagedThread(shared) , saved_call_frame_(0) , stack_start_(0) , profiler_(0) , run_signals_(false) , shared(shared) , waiter_(NULL) , om(shared.om) , interrupts(shared.interrupts) , check_local_interrupts(false) , thread_state_(this) , thread(this, (Thread*)Qnil) , current_fiber(this, (Fiber*)Qnil) { probe.set(Qnil, &globals().roots); set_stack_size(cStackDepthMax); }
void VM::set_current_fiber(Fiber* fib) { set_stack_start(fib->stack()); set_stack_size(fib->stack_size()); current_fiber.set(fib); }
matrix_mul::matrix_mul(sc_core::sc_module_name name, double period, sc_core::sc_time_unit unit, unsigned char id, unsigned char priority, bool verbose) :SpaceBaseModule(name, period, unit, id, priority, verbose) { SC_THREAD(thread); set_stack_size(0x16000+(300*300*4*3)); }
// return NULL if the tree cannot be constructed // return the constructed huffman tree // if you want to check for corruption of input file // check whether you have fully exhausted all bytes in // the header section to build the tree // tnode *Build_huffman_tree(FILE *infptr) { // you have to use to fseek to get to the right location of the file fseek(infptr,0,SEEK_SET); unsigned int fsize, hsize,csize; // to build the Huffman coding tree // First unsigned int in the file is the file size fread(&fsize,sizeof(unsigned int),1,infptr); // second unsigned int is the header size fread(&hsize,sizeof(unsigned int),1,infptr); // third unsigned int is the number of characters in the original file fread(&csize,sizeof(unsigned int),1,infptr); // initialize the stack, here, we have a dummy called stack // the code in list_tree.c assumes the presence of a dummy // the size of the stack is 0 lnode stack; stack.next = NULL; set_stack_size(&stack, 0); int token; // token to be read from the infptr int next = 0; tnode *tree; lnode *nodetree; lnode *elementl; lnode *elementr; tnode *treefin; int size = 0; // while we are in the header region // break from the loop when you cannot continue to build a tree // e.g. encountering EOF, asked to build a tree from two trees // on the stack, but the stack contains 0 or 1 tree. int count = 0; while (1) { // replace if necessary the correct condition token = fgetc(infptr); // get a character from the infptr count++; if (token == '1') { // what follows should be a character // read the character // build a tree that has a single tree node for that character // construct a list node with that tree node // push the list node onto the stack next = fgetc(infptr); tree = tree_construct(next, NULL, NULL); nodetree = node_construct(tree); push(&stack, nodetree); } else if (token == '0') { // You have to build a bigger tree from two trees in the list nodes // popped from the stack // After that, you have to push a list node containing the bigger // tree onto the stack // Beware of: (1) You can do the construction if there are // 2 or more items in the stack // (2) which of the two trees popped from the stack // is left and which is right of the bigger tree // (3) cleaning up so that you do not leak memory if (stack_size(&stack) < 2) { break; } if ((size = stack_size(&stack)) >= 2) { elementr = pop(&stack); elementl = pop(&stack); treefin = tree_construct(0,elementl->tree,elementr->tree); nodetree = node_construct(treefin); push(&stack, nodetree); free(elementr); free(elementl); } } } // check for the conditions that says that you have successfully // constructed a huffman coding tree: // you have exhausted all bytes in the header region of the file // you have exactly 1 item on the stack // in that case, the constructed huffman is contained in the // only list node on the stack, get it, and return the constructed tree // otherwise, return NULL // always clean up memory to avoid memory leak tnode *newtree = stack.next -> tree; free(stack.next); return newtree; }
// implement a stack with list // list would always have a dummy header // tree in dummy type-casted to store the size of stack (not counting the dummy) // void push(lnode *head, lnode *node) { node->next = head->next; head->next = node; set_stack_size(head, stack_size(head)+1); }