LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   pthreads and coffee (https://www.linuxquestions.org/questions/programming-9/pthreads-and-coffee-389480/)

smurff 12-05-2005 11:11 AM

pthreads and coffee
 
Ok, my story is as follows:

I have created a server app for work that reads records within a database does some boring stuff and write files. After a lot of coffee and more sleepless nights than when I had my 2 children, it was in a "good" beta phase. Tested it with a few million records and it works fine. Ok a mem leak here and there BUT it did take a few days to run :(

So I have looked at the code and it looks like its time for pthreads. I got a book of amazon which has helped me learn the basics but what I am asking you guys is as follows:

1: Whats the best way of implementing a safe "write to log" function? From what I can see, as long as I mutex the function to write I should be ok. But doesnt that create bottleknecks?

2: Although I am on Linux, I am actually coding this on my XP laptop and then recompiling. Has anyone used the pthreads for win or did you guys have some clever code that does stuff lilke IFDEF WIN32 Createthread... ELSE pthread...

Thanks guys
Smurff

dmail 12-05-2005 11:23 AM

1,yep mutex or a semaphore with a count of one. As for a bottle neck theres nothing you can do about that. :(
hmm thinking about this you only need it to write to a file. Im not 100% certain but think a file has a mutex.

2,Ive used the pthread win32 libray and its the best way of doing it as far as i was concerned.
http://sourceware.org/pthreads-win32/

smurff 12-05-2005 11:26 AM

Cheers dmail, Did you find any issues with using the win32 version? Thanks again for replying

dmail 12-05-2005 11:28 AM

the only issue(which is in the librarys readme) is which version to use depending on wether you want to catch errors(c++)

smurff 12-05-2005 11:35 AM

Good man thanks dmail


All times are GMT -5. The time now is 11:37 AM.