pthreads time slice problem

Started by
2 comments, last by the_edd 12 years, 2 months ago
Hi
I playing with pthreads and have problem with time slice ( 1 sec time slice )

Im on core to duo and make to threads which print different strings to console

Output is 1000 and more times first string and 1000 and more second and etc.

Any kind of idea how to make this simultaneously
Advertisement
This is the OpenGL forum.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Moving to the general programming forum.
I'm having a little difficulty understanding the question, but it sounds to me like you want fine-grained control over context switching. I'm also going to assume you aren;t on a strictly real-time target stack.

If that's so, then you quite probably shouldn't be using threads, or you're needlessly worrying about context switching granularity.

If you just want to interleave two sets of output, do so in a single thread. Otherwise let the OS take care of the context switching. This is the whole point of the "threads" abstraction. Some operating systems provide sys calls that provide a hint that the scheduler should 'yield' control of the current processing unit to another thread, but I really don't think that's what you want here; the (proper) usage of yield calls is very niche indeed (so I'm not even going to provide a link wink.png).

Also, if you're judging this by eye, based on the interleaving of console output, then console buffering may further be confusing the problem, depending on what exactly each thread is printing.

If you were to share the higher-purpose of this piece of code, then some helpful suggestions on approaches might be forthcoming.

This topic is closed to new replies.

Advertisement