Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 Date: Fri, 31 Oct 2003 11:01:55 +0100 From: manuela Subject: Possible bug about thread and semaphore X-Sender: manuelachessa AT pop DOT tiscali DOT it (Unverified) To: cygwin AT cygwin DOT com Message-id: <6.0.0.22.2.20031031105004.02468040@pop.tiscali.it> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Hi, I have a problem with this code with the last version of Cygwin (I run ipc-daemon2.exe). The program crashes after scanf ( I tested it also with fgets) if thread timer posted sem2 at least once. The same code works properly on Linux Suse 7.2 with gcc v. 3.3.1 and Red Hat with gcc v. 2.9.6. Is it my fault or Cygwin's fault? Bye Manuela Here follows my code: #include #include #include #include #include #include #include #include #include #define DIMBUFFER 20 void send_buffer(char *a); void * sender(void * arg); void * timer(void * arg); sem_t sem1; sem_t sem2; char buffer[DIMBUFFER]; void * sender(void * arg) { while(true) { sem_wait(&sem2); sem_wait(&sem1); send_buffer(buffer); buffer[0]='\0'; sem_post(&sem1); } } void * timer(void * arg) { while(true) { sleep(5); printf("Event\n"); sem_post(&sem2); } } int main(int argc, char *argv[]) { char string[DIMBUFFER]; buffer[0]='\0'; int ret; pthread_t id; pthread_t id2; ret = sem_init(&sem1,0,1); if(ret<0) { printf("error"); exit(1); } ret = sem_init(&sem2,0,0); if(ret<0) { printf("error"); exit(1); } int ret1= pthread_create(&id,NULL,sender,0); int ret2= pthread_create(&id2,NULL,timer,0); while(strcmp(string,"*")) { printf("inserisci stringa\n"); scanf("%s",string); sem_wait(&sem1); strcpy(buffer,string); sem_post(&sem1); sem_post(&sem2); } return 0; } void send_buffer(char *a) { if(strlen(a)) printf("%s\n",a); else printf("NULL\n"); } -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/