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 497039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:44:37+00:00 2026-05-13T05:44:37+00:00

Can anyone tell me how to insert a function call (say Yield() ) at

  • 0

Can anyone tell me how to insert a function call (say Yield() ) at random places inside a C function, so that each time the code is run, Yield() gets called from different parts of the code ?

I am faced with such a requirement as I’m using 2 threads in a cooperative threading environment , where unless the running thread yields the processor explicitly , the other (waiting) thread cannot start running. I don’t want to place the Yield() call at a single point , since that makes the thread sequence deterministic. Without rewiring the entire environment (from cooperative to pre-emptive) , this is the only solution I can think of in which Thread_1() makes the Yield() call at random places inside it, allowing Thread_2() to take over.

Any insights into a different solution achieving the same end-goals is also welcome!

  • 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-13T05:44:37+00:00Added an answer on May 13, 2026 at 5:44 am

    A BFI solution is called for, I think

    I think you will have to solve this the obvious way. You will need to make a wrapper for Yield() that makes a “random” decision on whether to call the real thing.

    If you are not concerned with execution speed then I would make it a real C function, and if you are I might suggest a preprocessor macro.

    So, something like:

    #define Yield0() ((random() & 0xf) == 0 && Yield())
    

    Choose the mask for the percentage chance of a call you want. For 0xf, and if random() has good low-order bit randomness, then you would see 1 Yield() in 16 calls. If you can use an MT or other high quality random number generator, the low order bits will be directly useful, otherwise you might want to random() >> 3 & ...

    And you will just need to put Yield0() calls everywhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me how to perform an insert query with Hibernate and back
Can anyone tell me how I can sort this: {'a': [1, 2, 3], 'c':
I am trying to insert an iAd thing into an existing app. Can anyone
i am going to call a function which will retrieve some data value from
OK, this feels like a question that should be easy to answer, but as
I am creating a new boost::thread using boost::bind , and storing it in a
I'm just getting started with android development, and I've ran into some problems my
I have a table called sample and it has a column called [__INSERT_DATE] which
Hi I'm using a asp:FormView and I need to set some inner control accessibility
I've made sure everything pertains to the column types in the database, but I

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.