In order to operate an aircraft in simulated instrument conditions, certain requirements must be met. 14 C.F.R. § 91.109(b) allows this type of operation in an aircraft equipped with fully functioning dual controls as long as "(1) the other control seat is occupied by a safety pilot who possesses at least a private pilot certificate with category and class ratings appropriate to the aircraft being flown; and (2) the safety pilot has adequate vision forward and to each side of the aircraft, or a competent observer in the aircraft adequately supplements the vision of the safety pilot." Unfortunately, Section 91.109(b) doesn't address the logging of flight time in connection with operations involving a safety pilot.
In order to understand how a pilot may "log" his or her flight time, it is important to keep in mind that "acting" or "serving" as a pilot in command ("PIC") or second in command ("SIC") during a flight is different than "logging time" for that flight. 14 C.F.R. 61.51(e) states that a pilot may log PIC time when (i) the pilot is the sole manipulator of the controls of an aircraft for which the pilot is rated; (ii) when the pilot is the sole occupant in the aircraft; or (iii) when the pilot acts as pilot in command of an aircraft for which more than one pilot is required under the type certification of the aircraft or the regulations under which the flight is conducted. Section 61.51(f) states that a pilot may log SIC time only for that flight time during which that person: (1) Is qualified in accordance with the second-in-command requirements of § 61.55 of this part, and occupies a crewmember station in an aircraft that requires more than one pilot by the aircraft's type certificate; or (2) Holds the appropriate category, class, and instrument rating (if an instrument rating is required for the flight) for the aircraft being flown, and more than one pilot is required under the type certification of the aircraft or the regulations under which the flight is being conducted.
Under these regulations, it is not possible for two pilots to "act" or "serve" as PIC simultaneously during a flight. However, it is possible for two pilots to log PIC flight time simultaneously. PIC flight time may be logged by both the PIC responsible for the operation and safety of the aircraft during flight time in accordance with 14 C.F.R. § 1.1 (e.g. the pilot "acting" or "serving" as PIC), and by the pilot who acts as the sole manipulator of the controls of the aircraft for which the pilot is rated.
So, in a typical simulated instrument flight, the pilot under the hood may log PIC time for that time in which he or she is the sole manipulator of the controls of the aircraft, provided that he or she is rated for that aircraft. The safety pilot may concurrently log as SIC time that time during which he or she is "acting" or "serving" as safety pilot (e.g. when the other pilot is actually under the hood) because the safety pilot is a required crewmember for operations under Section 91.109(b).
However, the two pilots may, prior to initiating the flight, agree that the safety pilot will be the PIC responsible for the operation and safety of the aircraft during the flight (e.g. the safety pilot will "act" or "serve" as PIC). In this situation, the safety pilot may log all the flight time as PIC time under Section 61.51(e)(iii), provided he or she is otherwise qualified to "act" or "serve" as a PIC (e.g. having a current flight review, appropriate ratings and endorsements etc.) and the pilot under the hood may log, concurrently, all of the flight time during which he or she is the sole manipulator of the controls as PIC time in accordance with Section 61.51(e)(i).
So you can see, depending upon the circumstances, a safety pilot may be able to both "act" as second in command or pilot in command and "log time" as second in command or pilot in command. In other situations, he or she may only be able to do one or the other. Although it can be tricky, airmen need to make sure they understand the distinction to ensure that they are logging their time accurately and in compliance with the regulations.