Multi-Threading and object lifecycle management

Source: Internet
Author: User

Many times we need to generate an object in thread A and then use this object in thread B. For example, thread a generates an Image object, and thread B uses this object to generate a texture. The simple thing is that thread A will first new an image object and then throw it to thread B, and thread B deletes it when it finishes using the object.

But if this object has other uses, such as I want to use this image data to synthesize some other data to generate a new texture, I don't need to recreate this object again. In addition, the new and delete this is very non-oriented, very unfriendly.

This article tries to give a new approach to the basic principle of who generates, who manages, who releases.

Thread A generates an object and passes it to thread B using and referencing the Count plus 1, and if thread C also needs this object, continue to pass the C-reference count plus 1. When thread B finishes using this object, the message queue tells thread A to run out, and thread A gets the message, minus 1 for the object reference. The message can also be a task, such as the task of simply reducing the object reference count by 1. All plus 1 minus 1 is executed in thread A, reducing the cost of mutually exclusive threads and accurately locating the object's life management.

Multi-Threading and object lifecycle management

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.