tags:

views:

116

answers:

5

Note the capital S on sleep.

Note, Sleep with a capital S is a standard function that sleeps milliseconds on the PC.

On the mac, under OSX, there is no such symbol.

But the xcode+linking environment seems to find something to link it to ...and I'm betting I won't like the answer.

A: 

The equivalent to sleep should be

[NSThread sleepForTimeInterval:5.0];

However this is in seconds. To use milliseconds I think you have to use usleep( num * 1000), where num is number of mills

But I don't know what Sleep(...) does

Preet Sangha
yes, I know how to sleep properly on the mac too. My question is, what is my cross-platform braino doing ?
ddyer
A: 

On the mac, under OSX, there is no such symbol.

I don't think there is such a symbol in Classic mac either - I even looked in my ancient copy of THINK Reference.

I would also be surprised to find a Sleep (with a capital S) function in C, since many people name C functions using all lower case.

Were you prompted to ask the question because you're getting a link error?

Seth
I think he's asking the question because he's (unexpectedly) _not_ getting a link error.
Logan Capaldo
I get a link error on a handy project that's just linking with the Carbon framework. It must be defined in something else.
Seth
A: 

There is usleep().

pthread_create(&pth,NULL,threadFunc,"foo");

while(i < 100)
{
    usleep(1);
    printf("main is running...\n");
    ++i;
}

printf("main waiting for thread to terminate...\n");
pthread_join(pth,NULL);

return 0;
ValiRossi
+5  A: 

Well, it’s an old old Carbon function (in the CoreServices / OSServices framework) that puts the computer to sleep. I can’t find any documentation.

jleedev
I'm pretty sure that's the correct answer, because that is the odd behavior I am seeing. Other bad things ensue, but the machine powers off it's monitor and disk.
ddyer
A: 

Are you using any other libraries in your project?

I'm getting compile errors using both Cocoa and Carbon using apple's template projects, however I notice that sleep functions (using the definition) are a feature in both the SDL and SFML cross platform libraries, and perhaps for many others.

Have you tried your code example on a template project using only with apples libraries?

It could be that Sleep() is a function in something else you are linking to.

Tomas Cokis