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 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: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , 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