Skip to content

Instantly share code, notes, and snippets.

@idank
Created April 8, 2013 09:17
Show Gist options
  • Save idank/5335474 to your computer and use it in GitHub Desktop.
Save idank/5335474 to your computer and use it in GitHub Desktop.
diff --git a/ut.c b/ut.c
index 8afe46c..88ebf7b 100644
--- a/ut.c
+++ b/ut.c
@@ -24,8 +24,7 @@ int ut_init(int tab_size)
tid_t ut_spawn_thread(void (*func)(int), int arg)
{
- ut_slot_t *p = ut_slots;
- p += sizeof(ut_slot_t)*thread_count;
+ ut_slot_t *p = ut_slots + thread_count;
p->stack = (char*)malloc(8912);
if (p->stack == NULL)
@@ -52,8 +51,7 @@ void handler(int signal)
{
if (signal == SIGVTALRM)
{
- ut_slot_t *p = ut_slots;
- p += sizeof(ut_slot_t)*currThreadNum;
+ ut_slot_t *p = ut_slots + currThreadNum;
p->vtime += 100;
printf("thread %d timer\n", currThreadNum);
}
@@ -63,8 +61,8 @@ void handler(int signal)
p = ut_slots;
t = ut_slots;
nextThreadNum = (currThreadNum + 1) % thread_count;
- p += sizeof(ut_slot_t)*currThreadNum;
- t += sizeof(ut_slot_t)*nextThreadNum;
+ p += currThreadNum;
+ t += nextThreadNum;
alarm(1);
printf("in handler, switch from %d to %d\n", currThreadNum, nextThreadNum);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment