Jump to content
Wisa

Fun stuff

Recommended Posts

Mi-a trimis un prieten un link de pe bash :))))

deya deea: iesi vecine prin centru mai pe dupa amiaza?

adrian bloc: nu ies ca e unchimiu la mine si il ajut cu ceva

deya deea: pai nu ai zis ca a venit ieri nicu la tine?

deya deea: ce cauta si azi?

adrian bloc: nu unchimiu nicu ma

deya deea: da care?

adrian bloc: ala de ti am zis ca i am baut slobozu din greseala cand eram mic

deya deea: looool =)) bashed nebunule

Link to comment
Share on other sites

Lucrez la un tool si aveam un thread care proceseaza ceva comenzi. Pe un quad core acel thread facea ca un core sa fie ocupat tot timpul. => 25% usage in acel program chiar cand nu facea nimic.

Problem solved:

private:

void beer()

{

usleep(10);

}

void run(){

while(!mStopRequested){

if(!mWorkerQueue.isEmpty()){

this->GetCommandOutput(mWorkerQueue.takeFirst());

}

beer(); // save CPU time - the answer to all problems

}

}

Link to comment
Share on other sites

Lucrez la un tool si aveam un thread care proceseaza ceva comenzi. Pe un quad core acel thread facea ca un core sa fie ocupat tot timpul. => 25% usage in acel program chiar cand nu facea nimic.

Problem solved:

private:

void beer()

{

usleep(10);

}

void run(){

while(!mStopRequested){

if(!mWorkerQueue.isEmpty()){

this->GetCommandOutput(mWorkerQueue.takeFirst());

}

beer(); // save CPU time - the answer to all problems

}

}

E mult prea mic intervalul, pune cel putin cateva milisecunde, nu microsecunde. E foarte posibil ca mecanismul de thread schedueling sa dureze mai mult (task switch-ul, salvarea registrilor si schimbarea pe un alt thread).

De asemenea: usleep(3) - Linux man page

[h=2]Errors[/h] EINTR Interrupted by a signal; see signal(7).

EINVAL

usec is not smaller than 1000000. (On systems where that is considered an error.)

4.3BSD, POSIX.1-2001. POSIX.1-2001 declares this function obsolete; use nanosleep(2) instead. POSIX.1-2008 removes the specification of usleep().

Cel mai probabil system call-ul dureaza mai mult decat sleep-ul propriu-zis.

Radem, glumim, dar suntem si seriosi :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...