473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to resolve this warning : 33 16 C:\Users\prcm\Documents\mutex.cpp [Error] 'sleep'

Hi ,

I am getting this error for a gcc compiler

33 16 C:\Users\prcm\Documents\mutex.cpp [Error] 'sleep' was not declared in this scope


I have included <unistd.h> as well but still i see the error.

How to resolve this?
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <pthread.h>
  3. #include <stdint.h>
  4. #include <unistd.h>
  5.  
  6. #define NUM 5
  7.  
  8. pthread_mutex_t mutex;
  9.  
  10. void* thread_f(void* par){
  11.         //int id = (int) par;    
  12.         int id = (intptr_t)par;
  13.     /*sleep waiting for the lock*/
  14.     pthread_mutex_lock(&mutex);
  15.         printf("Thread %d starting to work!\n",id);
  16.     pthread_mutex_unlock(&mutex);
  17.         return NULL;
  18. }
  19.  
  20. int main(){
  21.         pthread_t threads[NUM];
  22.         int i;
  23.  
  24.     /*initialize and lock mutex*/
  25.     pthread_mutex_init(&mutex, NULL);
  26.     pthread_mutex_lock(&mutex);
  27.  
  28.         for (i=0;i<NUM;i++){
  29.                 pthread_create(&threads[i],NULL,thread_f,(void *)i);
  30.         }
  31.  
  32.         printf("Everyone wait...\n");
  33.         sleep(1);
  34.         printf("Now go!\n");
  35.     /*wake one thread*/
  36.     pthread_mutex_unlock(&mutex);
  37.  
  38.     /*give the threads time to complete their tasks*/
  39.         sleep(1);
  40.  
  41.     printf("Main is quitting...\n");
  42.         return 0;
  43. }
  44.  
Jun 20 '14 #1
2 1410
weaknessforcats
9,208 Expert Mod 8TB
Have you added libc.lib to your linker library list?

Also, some implementations, like Windows, use Sleep and not sleep.
Jun 20 '14 #2
I guess, you need to include stdlib.h as well.
Jun 20 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mark A. Washburn | last post by:
/* Test4 WARNING THIS PROGRAM NEVER ENDS DUE TO JAVA COMPILER ERROR Neither Sun JDK 1.1.8 nor JDK 1.4.1 compiler will output *any* error or warning A disassembly of the class file shows...
2
by: Simon | last post by:
I have recently set up a server certificate on a web site. Under certain conditions I need to change the color of a html span element. I do this using the following javascript function called from...
0
by: bettina | last post by:
My Website works pretty good, except when it remains some minutes open without that any click will be made. For example, I'm in breweries.php (a subpage from index.php) and I make nothing except...
1
by: Dalan | last post by:
I'm experiencing a Query Syntax Error with an Access 97 Db. Actually, the query performs as expected when adding any new records or editing existing ones and even deleting records, EXCEPT when the...
14
by: PengYu.UT | last post by:
Hi, I have the following which has a bug (see the commented line). The one with the bug has the output of 10 -1073752704 The one without the bug has the output of 10
2
by: Akhila Jampala | last post by:
Hi, I am getting the below error whem i am running the crystal reports thru ASP: <p>Active Server Pages</font> <font face="Arial" size=2>error 'ASP 0115'</font> <p> <font face="Arial"...
0
by: bill gates | last post by:
I was trying to use msbee to build an old project. I don't want to upgrade to dotnet2.0. Is there any way to get this to compile using DevStudio 2005 using dotnet1.1. ? Build FAILED....
1
by: Girish Kanakagiri | last post by:
Hi, Can any one please resolve this compilation error. ..\DBAccess\Localization.cpp(381) : error C2593: 'operator + ' is ambiguous Error executing cl.exe DK_SSE_VCT.dll - 1 error(s), 0...
1
by: dewi | last post by:
Dear All, I am trying to compile a C code using Visual C++. Can anyone explain how to solve it? Thank You. #include <math.h> #include <string.h> #include "RV2AJFRONT_NEW.h" #include...
1
by: tochistochis | last post by:
Can you help me with this issue: "invalid top directory at /usr/lib/perl5/5.8.8/file/find.pm line 592" Here is my code: #!/usr/intel/bin/perl use strict; use warnings; use File::Find;
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.