This doesn't look ok:
(*tailcpu)->next = temp2;
*tailcpu = temp2;
(*tailcpu)->next = NULL;
See what you're doing - the first assignment sets (*tailcpu)->next
to temp2
. From now on, you lost reference to whatever was in (*tailcpu)->next
. Not only that, the next assignment (*tailcpu = temp2
) destroys whatever you wanted to achieve with the previous assignment.