C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 29th, 2006, 10:19 PM
irm_lexx's Avatar
irm_lexx irm_lexx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Posts: 253 irm_lexx User rank is Private First Class (20 - 50 Reputation Level)irm_lexx User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 19 h 40 m 27 sec
Reputation Power: 12
Pthread_cond_wait

Hi,

I have a thread 'A' that tells other threads 'B' to start and then it waits for all other threads 'B' to finish.
static pthread_cond_t condStart = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t mutexStart = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t condFinish = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t mutexFinish = PTHREAD_MUTEX_INITIALIZER;

in thread 'A'
pthread_cond_broadcast(&condStart,&mutexStart);

while(finishedCount<threadCount)
{
pthread_cond_wait(&condFinish,&mutexFinish);
finishedCount++;
}

in thread 'B'
pthread_cond_wait(&condStart,&mutexStart);
...do work....
pthread_cond_signal(&condFinish);


Sometimes, even though threads 'B' signal condFinish, thread 'A' does not recieve it...


Anyone knows whats going on?
__________________
Thank you for any help.

Reply With Quote
  #2  
Old October 30th, 2006, 01:53 AM
KitKat77's Avatar
KitKat77 KitKat77 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: planet<earth_like_t>
Posts: 365 KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 9 h 53 m 7 sec
Reputation Power: 147
Wel,, never used pthread meself so all I can start with is: are your variables finishedCount and threadCount properly initialized?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Pthread_cond_wait

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap