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
pthreads time slice problem
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 ).
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.
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 ).
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
Popular Topics
Advertisement