Calculating users share of a growing pool

Let’s say you have two pools,
The pool_1 is only growing with new users entering. It is earning rewards which are then put in a second pool_2 which then grows by auto compounding. New users enter the pool all the time. The users should be able to withdraw either their share of pool_1 , pool_2 or both.

How would you calculate each users share of the pool_2?

The thing I can’t come up with a simple solution for is, when a new user enters, I can’t give him a share of the existing pool_2. It would need some mechanism that factors in when this user entered the pool, so the program knows from when it should start including the new user in the growing rewards pool_2.

Maybe I’m looking at this the wrong way, let me know what you think!