Thread: pthread wrapper for embedded systems without pthread support

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    3

    pthread wrapper for embedded systems without pthread support

    Hi,

    I need to modify an embedded app which has been developed for RTLinux, and make it integrated with FreeRTOS instead; the problem at first glance is that FreeRTOS unlike RTLinux does not support POSIX, as a result, it seems that I should write a wrapper for pthread usages.

    I have found this link. I really your suggestions and also confirmations for what I found.

    Thanks in advance,
    Nadi

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I suggest the first thing you do is link all the object files without support for POSIX and get a nice list of unresolved symbols.

    This will be the set of functions you have to port, which could be a lot shorter than saying "I need a POSIX wrapper".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2013
    Posts
    3
    Thanks Salem.
    Would you clarify "link all the object files"? I have found all the functions and data types which use pthread and sys/mmap libraries which are POSIX-based, but they are a lot and may make my wrapper so complicated.
    Now, what is your suggestion?

    -Nadi

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Nadi View Post
    Thanks Salem.
    Would you clarify "link all the object files"? I have found all the functions and data types which use pthread and sys/mmap libraries which are POSIX-based, but they are a lot and may make my wrapper so complicated.
    Now, what is your suggestion?

    -Nadi
    Are you trying to make a general wrapper, or just something to be used for your app? If it's just for your app, you only need to re-write the functions that you actually use, rather than the entire library. Hence the suggestion to run the linker to see what symbols (ie functions) your code actually uses. (You know, the linker? The thing that runs after your code is compiled? Admittedly, gcc will generally run the linker for you after it compiles your code (unless you tell it to only compile), so you may well have never run the linker yourself (I don't think I have either). Assuming you have your cross-compiler makefile set up, you could just try to make the project and look for the unresolved symbol errors -- those are the things you need a wrapper for.)

  5. #5
    Registered User
    Join Date
    Nov 2013
    Posts
    3
    Quote Originally Posted by tabstop View Post
    Are you trying to make a general wrapper, or just something to be used for your app?
    Thanks a lot tabstop.

    I am trying to have something only be used for my app not a general one. So ,as I understood, it is better to re-write my required functions with regards to FreeRTOS libraries.
    I will come back very soon if I encountered linker problems, I hope to find you here again<

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
    Compile only
    $ gcc -c -pthread foo.c
    
    Link with all libs except pthread
    $ gcc -o a.out foo.o
    foo.o: In function `main':
    foo.c:(.text+0x38): undefined reference to `pthread_create'
    collect2: ld returned 1 exit status
    
    All unresolved symbols
    $ nm -u foo.o
                     U pthread_create
                     U puts
    Here is how you see what you actually need.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pthread hanging
    By munna_dude in forum C Programming
    Replies: 7
    Last Post: 05-17-2007, 08:51 AM
  2. The Pthread Hell
    By matott in forum Linux Programming
    Replies: 1
    Last Post: 04-10-2005, 05:59 AM
  3. Using pthread
    By mmondok in forum C Programming
    Replies: 3
    Last Post: 03-17-2003, 12:14 PM
  4. pthread problem 2
    By rotis23 in forum C Programming
    Replies: 1
    Last Post: 08-20-2002, 05:20 AM
  5. pthread problem
    By rotis23 in forum C Programming
    Replies: 1
    Last Post: 08-17-2002, 08:19 AM