Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6836425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:21:14+00:00 2026-05-26T23:21:14+00:00

see i have one library which has two api lets call api1() and api2()

  • 0

see i have one library which has two api lets call

api1() 

and

 api2()

Now internally api2 calls api1 also.

so in one situation i want to do is that

  • when some other application is calling api1() then do some special work
  • but when api2() calls api1() then do’nt do that special work.

how can i do that ?

Is there any way so i can know that api1() is calling from library itself not application?

Edit :

api1()
{
sem_wait();  // this create deadlock 

// do some task 

sem_post();
}

now api2() is like this

  api2()
{
sem_wait();

api1();

sem_post();

}

see my both function…when application calls api1() i need to be work in sem_wait and sem_post but when api2() calls api1() then i dont want to sem_wait again because its make dead locks …

i need some mechanism so api1() checks if it is being called from api2() then dont use sem_wait and sem_post

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:21:15+00:00Added an answer on May 26, 2026 at 11:21 pm

    Often done something like this:

    // internal function
    static int api1_internal(void) {
      do stuff assuming the lock is held;
    }
    
    // function for external callers, doing extra locking
    int api1(void) {
      int ret;
      lock();
      ret = api1_internal();
      unlock();
      return ret;
    }
    
    // some internal function using internal api1
    void internalfunc(void) {
      lock();
      do some things();
      api1_internal();
      unlock();
    }
    

    Note api1_internal is declared static to stop anything outside that file using it.

    If you really want to confuse yourself you could put the definition of api1() first, then have something like

    #define api1 api1_internal
    

    Which would keep your code pretty, but just confuse you later. Don’t do that.

    It’s common to use a leading underscore for internal, non-locking versions of functions, so

    static int _api1(void)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a library class which contains two methods, say, Login() and NavigateToPage(). Now,
I have set up a ruleset in my configuration file which has two validators,
I have one text input and one button (see below). How can I use
I have this control (see picture). I like when check one option in this
Do bubble sorts have any real world use? Every time I see one mentioned,
I have two Ruby arrays, and I need to see if they have any
my friend has made a really helpful class library which I use all the
I have a framework library which would do a lot of things including logging.
I have just started to look at the Scala collections library re-implementation which is
i am using ksoap library to call webservice in android. i dont see request

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.