delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/07/14/08:38:10

X-Recipient: archive-cygwin AT delorie DOT 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 DOT johnson AT cs DOT utoronto DOT 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 AT cygwin DOT com
Subject: Re: Pthread question for GDB?
References: <CADqjQ-++gmqPU37vNTFoHCQyrMhqsLmt9BKnmNuRysuxem4=og AT mail DOT gmail DOT com>
In-Reply-To: <CADqjQ-++gmqPU37vNTFoHCQyrMhqsLmt9BKnmNuRysuxem4=og@mail.gmail.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019