J
Johs32
I have made a pcb pointer called current. I have then made another pointer
(old_thread) that I initialize to point to the same area that current
points to.
If I make changes to current afterwards it also changes what old_thread
points to.
Why do old_thread change when I change current afterwards? If I make changes
to current AFTER copying it to old_thread, I don't see why this affects
old_thread.
struct pcb {
int state;
};
static struct pcb T1;
struct pcb *current = &T1;
struct pcb *old_thread = current;
printf("Before: %d\n",old_thread->state); //this prints 0
current->state = 222;
printf("After: %d\n",old_thread->state); // this prints 222
Why does the above code not print 0 in both cases? When I change current it
should not affect old_thread.
Johs
(old_thread) that I initialize to point to the same area that current
points to.
If I make changes to current afterwards it also changes what old_thread
points to.
Why do old_thread change when I change current afterwards? If I make changes
to current AFTER copying it to old_thread, I don't see why this affects
old_thread.
struct pcb {
int state;
};
static struct pcb T1;
struct pcb *current = &T1;
struct pcb *old_thread = current;
printf("Before: %d\n",old_thread->state); //this prints 0
current->state = 222;
printf("After: %d\n",old_thread->state); // this prints 222
Why does the above code not print 0 in both cases? When I change current it
should not affect old_thread.
Johs