1 /* tests/msr_dumb_while.c
3 * This requests the max_vcores in the system, then just while loops in a
4 * userthread. The pthread code will nicely yield if it detects an incoming
14 void *while_thread(void *arg)
19 int main(int argc, char** argv)
21 pthread_t *my_threads = malloc(sizeof(pthread_t) * max_vcores());
23 /* set up to receive the PREEMPT_PENDING event. EVENT_VCORE_APPRO tells the
24 * kernel to send the msg to whichever vcore is appropriate. Pthread code
25 * will see the preemption and yield. */
26 struct event_queue *ev_q = get_event_q();
27 ev_q->ev_flags = EVENT_IPI | EVENT_NOMSG | EVENT_VCORE_APPRO;
28 register_kevent_q(ev_q, EV_PREEMPT_PENDING);
30 /* actually only need one less, since the _S will be pthread 0 */
31 for (int i = 0; i < max_vcores() - 1; i++)
32 pthread_create(&my_threads[i], NULL, &while_thread, NULL);
34 assert(num_vcores() == max_vcores());
37 /* should never make it here */