Link to home
Start Free TrialLog in
Avatar of camster123
camster123

asked on

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.
Avatar of sarabande
sarabande
Flag of Luxembourg image

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
Avatar of camster123
camster123

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sarabande's solution was excellent , well documented with URLs and easy to read.