odd scheduler behavior?

odd scheduler behavior?

Post by Philippe A » Tue, 18 Apr 2006 02:27:53



Hi all,

I was experimenting with threads on QNX (1 CPU) and got some
behavior that seems odd to me.

the output clearly shows that threads run by groups of two only.

I tested on Linux (2 CPUs, nptl), it does the same thing.

[sorry, you need super-user priviledge to run this as it changes the
scheduling policy and priority.]

here is the code:

/****** thread.c ********/
#define _GNU_SOURCE
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

pthread_barrier_t bar;

void *thread_puts_stdout(void *s)
{
const char *str = s;
int i, j;

fprintf(stdout, "(start %s)", str);
pthread_barrier_wait(&bar);
fprintf(stdout, "(sync %s)", str);

for (i = 0 ; i != 100; ++i)
{
fputs(str, stdout);
for (j = 0; j != 1000000; ++j)
;
}
fprintf(stdout, "(done %s)", str);

return 0;
}

int main()
{
enum { num_thr = 3 };

pthread_t th[num_thr];
pthread_attr_t attr[num_thr];
struct sched_param schp[num_thr];
char *msg[] = { ".", "|", "#", "_", "^", "@" };
void *ret;
int i;

pthread_barrier_init(&bar, 0, num_thr);

for (i = 0; i != num_thr; ++i)
{
pthread_attr_init(&attr[i]);
pthread_attr_setschedpolicy(&attr[i], SCHED_RR);
pthread_attr_setinheritsched(&attr[i], PTHREAD_EXPLICIT_SCHED);
pthread_attr_getschedparam(&attr[i], &schp[i]);
schp[i].sched_priority = 99;
pthread_attr_setschedparam(&attr[i], &schp[i]);
}

for (i = 0; i != num_thr; ++i)
pthread_create(&th[i], &attr[i], thread_puts_stdout, msg[i]);

fprintf(stdout, "(join)");
for (i = 0; i != num_thr; ++i)
pthread_join(th[i], &ret);

fprintf(stdout, "(end)\n");
return 0;
}
/****** end thread.c **********/

output:

(start .)(start |)(start #)(sync #)###(sync |)|#|#|#|#|#|#|#|#|#|#|#|
#|#|#|#|#|#|#|#|#|#|#|#|#|#(sync .).#.#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#
|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#.#.#.#.
#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.(done #).....(join)|.|.|.|.
|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.(done |)...........
............................(done .)(end)


I did test using condition variables instead of barriers and it gives
the same result.

can someone explain this?

--
Philippe Amarenco, aka Phix
epita 2007 - GISTR - LSE - EpX
 
 
 

1. Odd behavior with odd code

2. odd behavior of first page/odd page/even page footers

I noticed something that I don't understand nor do I like the results. I
set up my document for odd/even footers and different first page
header/footers along with start with odd pages. I've set my margins for
0.9" on the left and 0.5" on the right and 0.5" for the top and bottom with
0.5" for header and footer gap along mirrored margins. When I printed the
first 20 pages I noticed that I had a different gap at the bottom of the odd
and even pages. The odd pages have about 1.0" of gap while the even pages
have a 0.5" gap. This problem doesn't show up with the headers for odd/even
pages. Any ideas as how to make them the same?

TIA,
Ken Erickson

3. My docs redirection and Printers -Odd odd odd

4. Different scheduler behavior between 2.4 and 2.6

5. ODBC & scheduler-Strange behavior

6. Unexpected behaviour of O(1) scheduler on SMP 2.6 Kernel

7. scheduler/SCHED_FIFO behaviour

8. CPU usage and strange behavior from the thread scheduler ?

9. smp 'nice' bias support breaks scheduler behavior

10. Odd Cursor Behaviour

11. Leban RTF2 odd Behavior

12. Odd Subform behavior in one field

13. Odd behaviour when disable combo box

14. Enablesand odd behavior

15. Odd behavior