UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old October 27th, 2004, 12:57 AM
fayya fayya is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Toronto
Posts: 58 fayya User rank is Private First Class (20 - 50 Reputation Level)fayya User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 10 h 48 m 42 sec
Reputation Power: 4
pthread_create() question

pthread_create() question

Hi, I understand there is this pthread_create() call in unix, but I don't really understand how it works, can anyone briefly explain how it works.

Actually I want to build a real-time clock by pthread to generate a child process, also with the system call gettimeofday, so when it passed 1ms, it signals the parent process and stored the # of times it signals the parent process in a variable.

Can anyone kind enough to supply a simple example or know if there's any site that is useful, thanks alot

Reply With Quote
  #2  
Old October 27th, 2004, 04:57 PM
fayya fayya is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Toronto
Posts: 58 fayya User rank is Private First Class (20 - 50 Reputation Level)fayya User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 10 h 48 m 42 sec
Reputation Power: 4
ok i've got to this far, basically now i declared a global variable "clock" and accumulate it whenever it passes 1ms, but i've got error message......

Quote:
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 1

double clock=0;

void *clockwait(void *threadid)
{

while(1) {

struct timeval first, second, last; // declare the timeval variables

gettimeofday(&first, NULL); // get the time at the first time
gettimeofday(&second, NULL); // get the time at the second time

last.tv_usec=second.tv_usec-first.tv_usec; // get the difference of the second and the first time collections
clock = clock + last.tv_usec;

}
}

int main(int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc, t;

printf("Creating thread %d\n", t);
rc = pthread_create(&threads[t], NULL, clockwait, (void *)t);

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

sleep(10);
printf("clock is %d", clock);
}


but i got this error message

edithello.c:15: `clock' redeclared as different kind of symbol
/usr/include/iso/time_iso.h:85: previous declaration of `clock'

what's wrong with my code?

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > pthread_create() question


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway