@@ -183,6 +183,9 @@ void dumpVal(VAL v) {
184 printf("] ");
184 printf("] ");
187+ printf("STR[%s]", v->info.str);
186 case FWD:
189 case FWD:
187 printf("FWD ");
190 printf("FWD ");
188 dumpVal((VAL)(v->info.ptr));
191 dumpVal((VAL)(v->info.ptr));
@@ -340,14 +343,11 @@ void* runThread(void* arg) {
340 ThreadData* td = (ThreadData*)arg;
343 ThreadData* td = (ThreadData*)arg;
341 VM* vm = td->vm;
344 VM* vm = td->vm;
343− printf("We're off\n");
345 TOP(0) = td->arg;
346 TOP(0) = td->arg;
346 BASETOP(0);
347 BASETOP(0);
347 ADDTOP(1);
348 ADDTOP(1);
348 td->fn(vm, NULL);
349 td->fn(vm, NULL);
350− printf("We're done\n");
351 free(td);
351 free(td);
@@ -358,20 +358,16 @@ void* vmThread(VM* callvm, func f, VAL arg) {
358 size_t stacksize;
358 size_t stacksize;
360 pthread_attr_init(&attr);
360 pthread_attr_init(&attr);
361− pthread_attr_getstacksize (&attr, &stacksize);
361+// pthread_attr_getstacksize (&attr, &stacksize);
362− pthread_attr_setstacksize (&attr, stacksize*64);
362+// pthread_attr_setstacksize (&attr, stacksize*64);
363− printf("Default stack size = %li\n", stacksize);
365 ThreadData *td = malloc(sizeof(ThreadData));
364 ThreadData *td = malloc(sizeof(ThreadData));
366 td->vm = vm;
365 td->vm = vm;
367 td->fn = f;
366 td->fn = f;
368 td->arg = copyTo(vm, arg);
367 td->arg = copyTo(vm, arg);
373− printf("Threading\n");
374 pthread_create(&t, &attr, runThread, td);
369 pthread_create(&t, &attr, runThread, td);
375 return vm;
371 return vm;
@@ -419,10 +415,11 @@ VAL copyTo(VM* vm, VAL x) {
419// Add a message to another VM's message queue
415// Add a message to another VM's message queue
420void sendMessage(VM* sender, VM* dest, VAL msg) {
416void sendMessage(VM* sender, VM* dest, VAL msg) {
421 VAL dmsg = copyTo(dest, msg);
417 VAL dmsg = copyTo(dest, msg);
422 pthread_mutex_lock(&(dest->inbox_lock));
419 pthread_mutex_lock(&(dest->inbox_lock));
424 *(dest->inbox_write) = dmsg;
421 *(dest->inbox_write) = dmsg;
426 dest->inbox_write++;
423 dest->inbox_write++;
427 if (dest->inbox_write >= dest->inbox_end) {
424 if (dest->inbox_write >= dest->inbox_end) {
428 dest->inbox_write = dest->inbox;
425 dest->inbox_write = dest->inbox;
@@ -441,10 +438,14 @@ void sendMessage(VM* sender, VM* dest, VAL msg) {
442// block until there is a message in the queue
439// block until there is a message in the queue
443VAL recvMessage(VM* vm) {
440VAL recvMessage(VM* vm) {
444− pthread_mutex_lock(&vm->inbox_block);
441+ VAL msg = NULL;
445− pthread_cond_wait(&vm->inbox_waiting, &vm->inbox_block);
443+ while (msg == NULL) {
444+ pthread_mutex_lock(&vm->inbox_block);
445+ pthread_cond_wait(&vm->inbox_waiting, &vm->inbox_block);
446+ pthread_mutex_unlock(&vm->inbox_block);
447− VAL msg = *(vm->inbox_ptr);
447+ msg = *(vm->inbox_ptr);
448 if (msg != NULL) {
449 if (msg != NULL) {
449 pthread_mutex_lock(&(vm->inbox_lock));
450 pthread_mutex_lock(&(vm->inbox_lock));
450 *(vm->inbox_ptr) = NULL;
451 *(vm->inbox_ptr) = NULL;
@@ -458,7 +459,7 @@ VAL recvMessage(VM* vm) {
458 exit(-1);
459 exit(-1);
461− pthread_mutex_unlock(&vm->inbox_block);
462+ return msg;
464void stackOverflow() {
465void stackOverflow() {