X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=0.1 required=5.0	tests=AWL,BAYES_40,SPF_NEUTRAL
X-Spam-Check-By: sourceware.org
Message-ID: <4E1EE31A.9030006@cs.utoronto.ca>
Date: Thu, 14 Jul 2011 08:37:46 -0400
From: Ryan Johnson <ryan.johnson@cs.utoronto.ca>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0
MIME-Version: 1.0
To: cygwin@cygwin.com
Subject: Re: Pthread question for GDB?
References: <CADqjQ-++gmqPU37vNTFoHCQyrMhqsLmt9BKnmNuRysuxem4=og@mail.gmail.com>
In-Reply-To: <CADqjQ-++gmqPU37vNTFoHCQyrMhqsLmt9BKnmNuRysuxem4=og@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

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

