Kernel: Do not use global variable as possible as you can try not to use global variables

Source: Internet
Author: User

And userspaceProgramYou must always consider using global variables with caution.

More intense kernel concurrency, multi-CPU operations, concurrent operations on multiple drivers, a carelessness may lead to a global variable uption.

In particular, when multiple devices use the same driver, this driver has multiple instances. At this time, the use of global variables will inevitably require consideration of the lock issue.

You can try to put the variables into the driver's private structure, which is much better. You only need to consider whether multiple CPUs will operate simultaneously.

In the userspace program, for example, when writing gstreamer plugin, global variables are also absolutely forbidden, because your Plugin may appear multiple times in a pipeline and thus have multiple instances.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.