Please contrast Ubuntu Linux with Red Hat Linux and Centos Linus in regards to porting Windows C++ file management functions, memory mapping function and multithreading functions.

Yesterday, I started porting Windows C++ file management functions, memory mapping function and multithreading functions to Ubuntu Linux where I used a makefile with g++. Subsequently, I discovered that including  <pthread.h> had to be augmented with #include  <bits/pthreadtypes.h >. Then , I discovered that the gettimeofday() function was not supported by Ubuntu Linux. I replaced the  gettimeofday() function with the time() function followed by localtime() to convert  it into struct tm.
    Please tell me if there are any more cases of this Ubuntu Linux behavior. Please contrast Ubuntu Linux with Red Hat Linux and Centos Linus in regards to porting Windows C++ file management functions, memory mapping function and multithreading functions.
    Any help is greatly appreciated.
camster123Senior C++ Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sarabandeCommented:
the conflicting types in pthread.h seems to be a known bug. you may try to not explictly including pthread.h at all what seemed to help for a source that included only stdio.h and stdlib.h.

gettimeofday should be available. try man pages.

if using stl file management functions are compatible beside that windows file names are not case sensitive and text files have carriage return - linefeed (CRLF) for line ending while unix files have a single linefeed.

for directories you may use direct.h for both windows and unix.

some posix functions and constants on windows require a preceding _ for example _stat function. however, you may try with out the underline. often windows has a macro or a typedef to support both names. if not, you may add such a definition to your own headers.  

memory mapping (files) is quite different. you may consider to add an own class which two platform-specific implementations.

for multi-threading you may use pthread for both. pthread for windows is available at many places for example by sourceware.org. alternatively you may use begin_thread to create threads and critical section as a fast mutex at windows and write wrapper classes for both. that should be good enough for most threading purposes.

Sara
1
camster123Senior C++ Software EngineerAuthor Commented:
sarabande,
 1. May I ask you to write a short code snippet illustrating your point
"the conflicting types in pthread.h seems to be a known bug. you may try to not explictly including pthread.h at all what seemed to help for a source that included only stdio.h and stdlib.h."?

  2. On Ubuntu LInx, when should I use STL file management functions  such as std::copy(..) instead of memcpy?
 

 3. May I ask for an concrete example of Ubuntu Linux  memory mapping (files) is quite different. I should consider to add an own class which two platform-specific implementations?

   Thank you.
0
sarabandeCommented:
to (1)

 i found a forum question with same 'conflicting types' error for the following code
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void* my_thread(void* arg)
{
        puts("I am a Thread!");
        return NULL;
}

int main()
{
        pthread_t trd;
        pthread_create(&trd, NULL, &my_thread, NULL);
        return 0;
}

Open in new window


the solution for the problem was to omit including pthread.h.

to (2)
with stl file management i meant std::ifstream and std::ofstream members rather than fopen, fread, fwrite (though the latter are compatible as well).

memcpy is ok. use memmove if copying memory that could overlap.

to (3)
see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2044.html for a unix sample of memory mapped files.

or

http://create.stephan-brumme.com/portable-memory-mapping/

Sara
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
camster123Senior C++ Software EngineerAuthor Commented:
Sarabande's solution was excellent , well documented with URLs and easy to read.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.