Pthread question for GDB?

Ryan Johnson ryan.johnson@cs.utoronto.ca
Thu Jul 14 12:37:00 GMT 2011


On 14/07/2011 5:43 AM, Jan Chludzinski wrote:
> If I'm stepping through main() in GDB, when I step past
> pthread_create() should the associated (newly created) thread begin
> executing independently of main() (i.e., the "main" thread)?
> Executing independently in the background?
Welcome to the jungle.

This has everything to do with the beast called parallelism and nothing 
to do with either cygwin or gdb (which is probably why you're not 
getting replies).

A short-running thread can easily complete before pthread_create returns.

Here's the law of the jungle, as simply put as I know: other threads can 
and will do *anything* they want, performing an arbitrary amount of 
work, in the time it takes the thread you're watching to execute a 
single machine instruction. Every time you assume otherwise you *will* 
be disappointed. This applies whether you're single stepping in gdb or not.

The only way around the above is to explicitly make threads wait for 
each other (which can easily slow your program down enough that it may 
as well be single-threaded). Go read up on races, critical sections, 
mutex locks, condition variables, semaphores, etc.

Ryan


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list