Jump to content

Warning About Code Called From 2 Threads


Recommended Posts

This isn't *just* about delay_us, that's just meant as an example.

 

I get this warning when i compile my program :-

 

Serious Warning: Possible sw stack corruption, function 'delay_us' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)

 

I understand that functions are not reentrant using sourceboost c.

In this case though I know that the function will only be called during initialisation from the main program, and once interrupts are enabled will never be called except from the interrupt handler.

 

Can I confirm that this is safe to do? (Even if there is a risk that I'll forget and call it from the main program too)

Is there any way to supress the message. I understand it's a valid warning but once I've understood that and made sure that my code will not call it at the same time from two threads it's just clutter that might make me miss other warnings.

Link to post
Share on other sites
Serious Warning: Possible sw stack corruption, function 'delay_us' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)

 

I understand that functions are not reentrant using sourceboost c.

In this case though I know that the function will only be called during initialisation from the main program, and once interrupts are enabled will never be called except from the interrupt handler.

 

Can I confirm that this is safe to do? (Even if there is a risk that I'll forget and call it from the main program too)

Yes this will be safe as long as the routine is not called from both threads at the same time. Disabling interrupts before calling and enabling after calling the routine in the main execution thread would make this safe.

 

Is there any way to supress the message. I understand it's a valid warning but once I've understood that and made sure that my code will not call it at the same time from two threads it's just clutter that might make me miss other warnings.
No this message can't currently be disabled, but I appreaciate that you don't want to be looking for one real warning in a sea of normally occuring ones.

 

Regards

Dave

Link to post
Share on other sites

Ok thanks, good news for me that it's safe anyway.

 

Can I add a feature request for a way to disable the warning on a function by function basis (I wouldn't want to supress the message for unexpected misuses).

It would be handy if you could put a #pragma before a function with two options

 

1) Disable the warning for calling that function

2) "Clone" the function for each thread it is called from.

 

Low priority but would be a handy enhancement.

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...