delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/02/05/13:44:29

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
From: Gaurav Sachdeva <sachdeva DOT gaurav AT gmail DOT com>
Date: Sat, 6 Feb 2010 00:13:59 +0530
Message-ID: <ce3537cc1002051043l57cdeef2j268592189cc9c24@mail.gmail.com>
Subject: pthread problem
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes
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

Hi,

I have written following code -

#include<stdio.h>

void *thread_func(void *data)
{
  printf("In thread\n");
  pthread_exit(NULL);
}

int main()
{
  pthread_t mythread;
  int rc;

  rc = pthread_create(&mythread, NULL, thread_func, NULL);
  if (rc){
         printf("ERROR; return code from pthread_create() is %d\n", rc);
         exit(-1);
      }

  printf("In main..\n");

  pthread_exit(NULL);
}

It must print both "In main" and "In thread".
But sometimes it prints one of these two and sometimes both.
I tried in actual UNIX OS. It always prints both.

I also tried in c++ in cygwin, problem exists there also.

Is anyone aware of this problem and its solutions?

Thanks,
Gaurav

--
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