My question is about good coding practice. Consider the following code architecture that I have right now:
The functions of the main task (task A) create task B through the API provided by the submodule translation unit. This init_task_b function heap allocates space for the info struct, creates the task B and stores its handle along with some additional information in the info struct. The structs address is then returned to task A functions where it is stored in a static variable. At the same time in the task_b_init-function, the structs address is passed on to task B, where task B uses some of the information stored in the info-struct to operate.
The question is: Is this good practice? Because both tasks, A and B use the same struct, it could happen that it gets deleted by task A and task B is left with a nullpointer. However, this shouldn’t happen as the struct is only to be modified by task B API-Functions. Still… I’m left wondering. What do you think?
EDIT: I just read the linux kernel style guide where it was hinted that using an opaque struct (struct keyword typedefed away) is only allowed for use in accessor functions, to so say “force” the user to use the accessor functions. In the case of my info-struct, would this make the above architecture valid?