Cancer is certainly no laughing matter, but writer Will Reiser and director Jonathan Levine manage to extract plenty of lighthearted moments, and some downright hilarious ones, from it in “50/50.” But of course they aim for the heartstrings as well as the funnybone in the film, which offers comic riffs embedded in serious underpinnings.

The fact that the story derives from Reiser’s own experience as a cancer survivor is certainly a major factor in the picture’s success, giving it a sense of truthfulness it would otherwise surely lack. But an even stronger element lies in the fact that Adam Lerner, the young man diagnosed with a potentially fatal spinal tumor who’s Reiser’s surrogate, is played by Joseph Gordon-Levitt. He’s one of the best actors of his generation, and has in the past proven himself equally adept at comedy and drama. He brings both aspects to bear here in a performance that’s both amusing and touching.

Lerner works at a Seattle PBS station, and while a pleasant fellow is also reserved, cautious and health-conscious—in every respects the polar opposite of his voluble, sloppy best buddy Kyle (Seth Rogen). Adam also has a beautiful live-in girlfriend, Rachael (Bryce Dallas Howard), who neglects no opportunity to show her devotion o him but obviously has ambitions of her own.

The unexpected strikes when Adam visits a doctor for a diagnosis about back pain and tests reveal a far more serious condition than he’d ever imagined, one that will require powerful chemotherapy prior to surgery. When he tells his mother Diane (Anjelica Huston), she predictably reacts hysterically, but turns out to be remarkably supportive, even though she’s already coping with her husband’s Alzheimer’s. And contrary to expectations, Kyle remains a steadfast friend, though of course Rogen plays him as Rogen—a smart-ass wiseacre. (Of course, Rogen and his partner Evan Goldberg, who with Ben Karlin produced “50/50,” actually were close friends and colleagues of Reiser when he was stricken. So the authenticity of their relationship is grounded in actual experience, too.) But Rachael proves incapable of dealing with the situation and decamps.

Fortunately, Adam has Kyle and his mother to lean on. And there are other sources of support as well. Among them are the elderly, cantankerous guys he meets during chemo sessions—particularly Alan (Philip Baker Hall) and Mitch (Matt Frewer)—characters these canny actors endow with plenty of humor and an equal measure of poignancy. And there’s Katherine (Anna Kendrick), the nervous, inexperienced therapist to whom Adam is sent for counseling. Unaccustomed to so young a patient and ill-equipped to deal with him confidently, she fumbles the treatment, but the two inevitably grow closer, particularly off the clock, and gradually the patient-client relationship becomes something more personal.

“50/50” is an uneven mixture of comedy and drama, with some of the humor going too far toward the Apatow playbook Rogen knows so well and some of the more serious moments inching perilously close to mawkishness. But it manages to sidestep most of the hurdles because of the grace notes in Reiser’s script that arise from his own experience and from Levine’s generally restrained direction, which wisely holds back when it might have let loose.

And it benefits from the acting. Howard mitigates the shrillness of her character, and Huston doesn’t permit Diane to degenerate into broad caricature, as might easily have happened. Hall and Frewer play their scenes with the assurance of a pair of vaudeville hoofers. Kendrick makes Katherine’s clumsy lack of confidence endearing rather than frustrating. And even Rogen—though he can’t stop playing the same person he always does, himself—tamps down the exuberance in the final reel to show a touch of sensitivity to go along with the bravado.

But it’s Gordon-Levitt who seals the deal. In a turn far removed from his over-the-top “Hesher” performance, he perfectly captures the shy, reticent quality of the nice, thoughtful guy you can’t help but like. Here’s another young actor—like Edward Norton and Ryan Gosling—who can run the gamut from raging ferocity to simple pleasantness and make both absolutely credible.

Technically there’s nothing eye-popping about “50/50,” but it’s perfectly adequate down the line, from Terry Stacey’s cinematography and Zene Baker’s editing to Michael Giacchino’s score (supplemented by some pop tunes). It’s not a perfect film, but there’s a better than even chance that you’ll find it both funny and touching.