multithreading - Detecting when an object is passed to a new thread in C++? -


I have an object for which I want to track the number of referenced threads. In general, when any method is called on the object, I can check the local boolean value, to determine if the count for the current thread has been updated. But if the user says that does not help me then to promote: Forcing my object to promote: Function and Promotion: Thread to promote the new thread will be in reference to my object, and It can hold it for an indefinite period before calling any of its ways, thus a stale count can be extended to increase its own cover to promote it I can give: Thread, but if the user does not help in promoting: the object of the bind in which is my object (I'm not a specialist based on that of a member type - at least I do not know any way to do this) and to promote: Uses the thread to start.

Is there any way to do this? The only thing that I can think is that users need a lot of work - I provide a cover around the promotion: The thread in which the particular hook method in the present object is called, and the user has any class I add special hook method to it in my aim.

EDIT: For this question, we can assume that I control the means of making new sources. That's why I can wrap the promotion :: thread for example and expect that users will use my wrapped version, and users will not have to worry about using pthreads etc. together.

Edit2: Anyone can assume that I have some threads through local storage devices, __ thread or boost :: thread_specific_ptr is available. It is not in the current standard, but hopefully that will happen soon.

In general, it is difficult. The question of "Which reference do I have?" Generally, you are trying to solve the specific problem (circles) that are not solvable in C ++, and if you are looking better, you might be able to see the big picture.

There are some things you can come from that you participate there, but none of these is very much for you.

You can install the concept of "3D Thread" for any object, and any other thread will have to regect operation, La QT GUI element. (Note that by trying to thread things in a thread other than the owner, you will not actually get yarn security, because if the owner has not been investigated, then it is able to collide with another thread. Maybe.) This at least failed your users - fast behavior.

You can encourage context-visual by having a user-visible object with light references [and by documenting it!] For the implementation object. But the fixed users can work on this.

And you can add these two - that is, you can get the perception of thread ownership for each context , and after that the object can be aware of which It is the owner of the context, it can be very powerful, but not really stupid-proof.

You can restrict what users can and can not do with the object, but I think that the unknowingly obvious source of error is worthwhile. Do you have the operator & amp; Private, then people can not signal their objects? Are you blocking people from dynamically allocating your object? It depends on your users to a certain degree, but keep in mind that you can not stop context on the object, so ultimately play funny-one-sesame will make you crazy.

Then, return to my original idea: if possible, re-analyze the big picture.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -