FreeBSD Bugzilla – Attachment 146162 Details for
Bug 192926
[patch] sched_yield is a no-op
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
test case
yield_noop.c (text/x-c), 1.97 KB, created by
eric
on 2014-08-22 18:24:46 UTC
(
hide
)
Description:
test case
Filename:
MIME Type:
Creator:
eric
Created:
2014-08-22 18:24:46 UTC
Size:
1.97 KB
patch
obsolete
>// cc -lpthread -o yield_noop yield_noop.c >// >// failure: worker is NOT making progress >// success: worker is making progress > >#include <sys/cdefs.h> >#include <sys/param.h> >#include <sys/cpuset.h> > >#include <err.h> >#include <pthread.h> >#include <pthread_np.h> >#include <stdio.h> >#include <unistd.h> > >static unsigned int worker_counter = 0; > >static void * >yielding_thread_func(void *arg __unused) >{ > for (;;) > pthread_yield(); > > return (NULL); >} > >static void * >worker_thread_func(void *arg __unused) >{ > char dot = '.'; > > for (;;) { > sleep(1); > write(STDERR_FILENO, &dot, sizeof(dot)); > ++worker_counter; > } > > return (NULL); >} > >int >main(int argc __unused, char *argv[] __unused) >{ > int error; > pthread_t yielding_thread, worker_thread; > pthread_attr_t thread_attr; > cpuset_t cpuset; > const unsigned int sleep_time = 4; > > error = pthread_attr_init(&thread_attr); > if (error) > errc(1, error, "pthread_attr_init"); > > error = pthread_attr_setinheritsched(&thread_attr, PTHREAD_EXPLICIT_SCHED); > if (error) > errc(1, error, "pthread_attr_setinheritsched"); > > error = pthread_attr_setschedpolicy(&thread_attr, SCHED_FIFO); > if (error) > errc(1, error, "pthread_attr_setschedpolicy"); > > // Bind both threads to the same CPU. > CPU_ZERO(&cpuset); > CPU_SET(0, &cpuset); > > error = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpuset), &cpuset); > if (error) > errc(1, error, "pthread_attr_setaffinity_np"); > > error = pthread_create(&yielding_thread, &thread_attr, yielding_thread_func, NULL); > if (error) > errc(1, error, "pthread_create(yielding_thread)"); > > error = pthread_create(&worker_thread, &thread_attr, worker_thread_func, NULL); > if (error) > errc(1, error, "pthread_create(worker_thread)"); > > sleep(sleep_time); > printf("worker is%s making progress: %d\n", > (worker_counter >= sleep_time - 1) ? "" : " NOT", > worker_counter); > > return (0); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 192926
:
146161
| 146162