Home > Articles

Synchronization

The final part of concurrent programming, synchronization, involves goroutines -race3 flag, sync.Mutex4, sync.RWMutex.5, and sync.Once.

This chapter is from the book

This chapter is from the book

In Chapter 11, we explained how to use channels for passing data between goroutines. Then in Chapter 12, we discussed how to use the context1 package to manage the cancellation of goroutines. In this chapter, we cover the final part of concurrent programming: synchronization.

We show you how to wait for a number of goroutines to finish. We explain race conditions,2 how to find them using Go’s -race3 flag, and how to fix them with sync.Mutex4 and sync.RWMutex.5

Finally, we discuss how to use sync.Once to ensure a function is only executed one time.

Waiting for Goroutines with a WaitGroup

Often, you might want to wait for a number of goroutines to finish before you continue your program. For example, you might want to spawn a number of goroutines to create a number of thumbnails of different sizes and wait for them all to complete before you continue.

The Problem

Consider Listing 13.1. We launch 5 new goroutines, each of which creates a thumbnail of a different size. We then wait for all of them to complete.

Listing 13.1 Launching Multiple Goroutines to Complete One Task
func Test_ThumbnailGenerator(t *testing.T) {
    t.Parallel()

    // image that we need thumbnails for
    const image = "foo.png"

    // start 5 goroutines to generate thumbnails
    for i := 0; i < 5; i++ {

        // start a new goroutine for each thumbnail
        go generateThumbnail(image, i+1)

    }

    fmt.Println("Waiting for thumbnails to be generated")
}

The generateThumbnail function, Listing 13.2, generates a thumbnail of the specified size. In this example, we sleep one millisecond per “size” of thumbnail to simulate the time it takes to generate the thumbnail. For example, if we call generateThumbnail("foo.png", 200), we sleep 200 milliseconds before returning.

Listing 13.2 A Test Exiting before All Goroutines Have Finished
func generateThumbnail(image string, size int) {

    // thumbnail to be generated
    thumb := fmt.Sprintf("%s@%dx.png", image, size)

    fmt.Println("Generating thumbnail:", thumb)

    // wait for the thumbnail to be ready
    time.Sleep(time.Millisecond * time.Duration(size))

    fmt.Println("Finished generating thumbnail:", thumb)
}

$ go test -v

 === RUN   Test_ThumbnailGenerator
 === PAUSE Test_ThumbnailGenerator
 === CONT  Test_ThumbnailGenerator
 Waiting for thumbnails to be generated
 --- PASS: Test_ThumbnailGenerator (0.00s)
 PASS
 ok      demo    0.408s

Go Version: go1.19

As you can see from the test output in Listing 13.2, the test exits before the thumbnails are generated.

Our tests exit prematurely because we have not provided any mechanics to ensure that we wait for all of the thumbnail goroutines to finish before we continue.

Using a WaitGroup

To help us solve this problem, we can use a sync.WaitGroup,6 Listing 13.3, to track how many goroutines are still running and notify us when they have all finished.

Listing 13.3 The sync.WaitGroup Type
$ go doc -short sync.WaitGroup

type WaitGroup struct {
        // Has unexported fields.
}
    A WaitGroup waits for a collection of goroutines to finish. The main
    arrow.jpggoroutine calls Add to set the number of goroutines to wait for. Then
    arrow.jpgeach of the goroutines runs and calls Done when finished. At the same
    arrow.jpgtime, Wait can be used to block until all goroutines have finished.

    A WaitGroup must not be copied after first use.

func (wg *WaitGroup) Add(delta int)
func (wg *WaitGroup) Done()
func (wg *WaitGroup) Wait()

Go Version: go1.19

The principle is simple: We create a sync.WaitGroup and use the sync.WaitGroup.Add7 method to add to the sync.WaitGroup for each goroutine we want to wait for. When we want to wait for all of the goroutines to finish, we call the sync.WaitGroup.Wait8 method. When a goroutine finishes, it calls the sync.WaitGroup.Done9 method to indicate that the goroutine is finished.

The Wait Method

As the name suggests, a sync.WaitGroup is about waiting for a group of tasks, or goroutines, to finish. To do this, we need a way of blocking until all of the tasks have finished. The sync.WaitGroup.Wait method in Listing 13.4 does exactly that.

The sync.WaitGroup.Wait method blocks until its internal counter is zero. When the counter is zero, it means that all of the tasks have finished, and we can unblock and continue.

Listing 13.4 The sync.WaitGroup.Wait Method
$ go doc sync.WaitGroup.Wait

package sync // import "sync"

func (wg *WaitGroup) Wait()
    Wait blocks until the WaitGroup counter is zero.

Go Version: go1.19

The Add Method

For a sync.WaitGroup to know how many goroutines it needs to wait for, we need to add them to the sync.WaitGroup using the sync.WaitGroup.Add method, Listing 13.5.

Listing 13.5 The sync.WaitGroup.Add Method
$ go doc sync.WaitGroup.Add

package sync // import "sync"

func (wg *WaitGroup) Add(delta int)
    Add adds delta, which may be negative, to the WaitGroup counter.
    arrow.jpgIf the counter becomes zero, all goroutines blocked on Wait are released.
    arrow.jpgIf the counter goes negative, Add panics.

    Note that calls with a positive delta that occur when the counter is
    arrow.jpgzero must happen before a Wait. Calls with a negative delta, or calls
    arrow.jpgwith a positive delta that start when the counter is greater than zero,
    arrow.jpgmay happen at any time. Typically this means the calls to Add should
    arrow.jpgexecute before the statement creating the goroutine or other event to be
    arrow.jpgwaited for. If a WaitGroup is reused to wait for several independent
    arrow.jpgsets of events, new Add calls must happen after all previous Wait calls
    arrow.jpghave returned. See the WaitGroup example.

Go Version: go1.19

The sync.WaitGroup.Add method takes a single integer argument, which is the number of goroutines to wait for. There are, however, some caveats to be aware of.

Adding a Positive Number

The sync.WaitGroup.Add method accepts an int argument, which is the number of goroutines to wait for. If we pass a positive number, the sync.WaitGroup.Add method adds that number of goroutines to the sync.WaitGroup.

As you can see from the test output in Listing 13.6, the sync.WaitGroup.Wait method blocks until the internal counter of the sync.WaitGroup reaches zero.

Listing 13.6 Adding a Positive Number of Goroutines
func Test_WaitGroup_Add_Positive(t *testing.T) {
    t.Parallel()

    var completed bool

    // create a new waitgroup (count: 0)
    var wg sync.WaitGroup

    // add one to the waitgroup (count: 1)
    wg.Add(1)

    // launch a goroutine to call the Done() method
    go func(wg *sync.WaitGroup) {

        // sleep for a bit
        time.Sleep(time.Millisecond * 10)

        fmt.Println("done with waitgroup")

        completed = true

        // call the Done() method to decrement
        // the waitgroup counter (count: 0)
        wg.Done()
    }(&wg)

    fmt.Println("waiting for waitgroup to unblock")

    // wait for the waitgroup to unblock (count: 1)
    wg.Wait()
    // (count: 0)

    fmt.Println("waitgroup is unblocked")

    if !completed {
        t.Fatal("waitgroup is not completed")
    }
}

$ go test -v -run Positive

=== RUN   Test_WaitGroup_Add_Positive
=== PAUSE Test_WaitGroup_Add_Positive
=== CONT  Test_WaitGroup_Add_Positive
waiting for waitgroup to unblock
done with waitgroup
waitgroup is unblocked
--- PASS: Test_WaitGroup_Add_Positive (0.01s)
PASS
ok      demo    0.351s

Go Version: go1.19

Adding a Zero Number

It is legal to call the sync.WaitGroup.Add method with a zero number, 0, Listing 13.7. In this case, the sync.WaitGroup.Add method does nothing. The call becomes a no-op.

Listing 13.7 Adding a Zero Number of Goroutines
func Test_WaitGroup_Add_Zero(t *testing.T) {
    t.Parallel()

    // create a new waitgroup (count: 0)
    var wg sync.WaitGroup

    // add 0 to the waitgroup (count: 0)
    wg.Add(0)
    // (count: 0)

    fmt.Println("waiting for waitgroup to unblock")

    // wait for the waitgroup to unblock (count: 0)
    // will not block since the counter is already 0
    wg.Wait()
    // (count: 0)

    fmt.Println("waitgroup is unblocked")
}

$ go test -v -run Zero

=== RUN   Test_WaitGroup_Add_Zero
=== PAUSE Test_WaitGroup_Add_Zero
=== CONT  Test_WaitGroup_Add_Zero
waiting for waitgroup to unblock
waitgroup is unblocked
--- PASS: Test_WaitGroup_Add_Zero (0.00s)
PASS
ok      demo    0.166s

Go Version: go1.19

As you can see from the test output in Listing 13.7, the sync.WaitGroup.Wait method unblocked immediately because its internal counter is already zero.

Adding a Negative Number

When calling the sync.WaitGroup.Add method with a negative number, the sync.WaitGroup.Add method panics.

As you can see from the test output in Listing 13.8, the sync.WaitGroup.Wait method was never reached because the sync.WaitGroup.Add method panicked when we tried to add a negative number of goroutines.

Listing 13.8 Adding a Negative Number of Goroutines
func Test_WaitGroup_Add_Negative(t *testing.T) {
    t.Parallel()

    // create a new waitgroup (count: 0)
    var wg sync.WaitGroup

    // use an anonymous function to trap the panic
    // so we can properly mark the test as a failure
    func() {

        // defer a function to catch the panic
        defer func() {
            // recover the panic
            if r := recover(); r != nil {
                // mark the test as a failure
                t.Fatal(r)
            }
        }()

        // add a negative number to the waitgroup
        // this will panic since the counter cannot be negative
        wg.Add(-1)

        fmt.Println("waiting for waitgroup to unblock")

        // this will never be reached
        wg.Wait()

        fmt.Println("waitgroup is unblocked")
    }()

}

$ go test -v -run Negative

=== RUN   Test_WaitGroup_Add_Negative
=== PAUSE Test_WaitGroup_Add_Negative
=== CONT  Test_WaitGroup_Add_Negative
    add_test.go:92: sync: negative WaitGroup counter
--- FAIL: Test_WaitGroup_Add_Negative (0.00s)
FAIL
exit status 1
FAIL    demo    0.753s

Go Version: go1.19

The Done Method

Once we increase that counter by calling the sync.WaitGroup.Add method, the sync.WaitGroup.Wait method blocks until we decrement the counter as we finish with each goroutine.

For each item we add to the sync.WaitGroup with the sync.WaitGroup.Add method, we need to call the sync.WaitGroup.Done method, Listing 13.9, to indicate that the goroutine is finished.

Listing 13.9 The sync.WaitGroup.Done method
$ go doc sync.WaitGroup.Done

package sync // import "sync"

func (wg *WaitGroup) Done()
    Done decrements the WaitGroup counter by one.

Go Version: go1.19

Consider Listing 13.10, which creates N goroutines and adds N to the sync.WaitGroup using the sync.WaitGroup.Add method. Each goroutine calls the sync.WaitGroup.Done method after it finishes. We then use the sync.WaitGroup.Wait method to wait for all of the goroutines to finish.

Listing 13.10 Testing the sync.WaitGroup.Done Method
func Test_WaitGroup_Done(t *testing.T) {
    t.Parallel()

    const N = 5

    // create a new waitgroup (count: 0)
    var wg sync.WaitGroup

    // add 5 to the waitgroup (count: 5)
    wg.Add(N)

    for i := 0; i < N; i++ {

        // launch a goroutine that will call the
        // waitgroup's Done method when it finishes
        go func(i int) {

            // sleep briefly
            time.Sleep(time.Millisecond * time.Duration(i))

            fmt.Println("decrementing waiting by 1")

            // call the waitgroup's Done method
            // (count: count - 1)
            wg.Done()
        }(i + 1)
    }

    fmt.Println("waiting for waitgroup to unblock")

    wg.Wait()

    fmt.Println("waitgroup is unblocked")
}

$ go test -v -timeout 1s

=== RUN   Test_WaitGroup_Done
=== PAUSE Test_WaitGroup_Done
=== CONT  Test_WaitGroup_Done
waiting for waitgroup to unblock
decremeting waiting by 1
decremeting waiting by 1
decremeting waiting by 1
decremeting waiting by 1
decremeting waiting by 1
waitgroup is unblocked
--- PASS: Test_WaitGroup_Done (0.01s)
PASS
ok      demo    0.384s

Go Version: go1.19

As we can see from the test output, Listing 13.10, the sync.WaitGroup.Wait method unblocked after all of the goroutines finished.

Improper Usage

If you don’t call sync.WaitGroup.Done exactly once for each item you add with sync.WaitGroup.Add, the sync.WaitGroup.Wait method will block forever, which causes a deadlock and crashes your program, as shown in Listing 13.11.

Listing 13.11 Decrementing a sync.WaitGroup with the sync.WaitGroup.Done Method
func Test_WaitGroup_Done(t *testing.T) {
    t.Parallel()

    const N = 5

    // create a new waitgroup (count: 0)
    var wg sync.WaitGroup

    // add 5 to the waitgroup (count: 5)
    wg.Add(N)

    for i := 0; i < N; i++ {

        // launch a goroutine that will call the
        // waitgroup's Done method when it finishes
        go func(i int) {

            // sleep briefly
            time.Sleep(time.Millisecond * time.Duration(i))

            fmt.Println("finished")

            // exiting with calling the Done method
            // (count: count)
        }(i + 1)
    }

    fmt.Println("waiting for waitgroup to unblock")

    // this will never unblock
    // because the goroutines never call Done
    // and the application will deadlock and panic
    wg.Wait()

    fmt.Println("waitgroup is unblocked")

}

$ go test -v -timeout 1s

=== RUN   Test_WaitGroup_Done
=== PAUSE Test_WaitGroup_Done
=== CONT  Test_WaitGroup_Done
waiting for waitgroup to unblock
finished
finished
finished
finished
finished
panic: test timed out after 1s

goroutine 19 [running]:
testing.(*M).startAlarm.func1()
    /usr/local/go/src/testing/testing.go:2029 +0x8c
created by time.goFunc
    /usr/local/go/src/time/sleep.go:176 +0x3c

goroutine 1 [chan receive]:
testing.tRunner.func1()
    /usr/local/go/src/testing/testing.go:1405 +0x45c
testing.tRunner(0x140001361a0, 0x1400010fcb8)
    /usr/local/go/src/testing/testing.go:1445 +0x14c
testing.runTests(0x1400001e280?, {0x101045ea0, 0x1, 0x1},
arrow.jpg{0x6e00000000000000?, 0x100e71218?, 0x10104e640?})
    /usr/local/go/src/testing/testing.go:1837 +0x3f0
testing.(*M).Run(0x1400001e280)
    /usr/local/go/src/testing/testing.go:1719 +0x500
main.main()
    _testmain.go:47 +0x1d0

goroutine 4 [semacquire]:
sync.runtime_Semacquire(0x0?)
    /usr/local/go/src/runtime/sema.go:56 +0x2c
sync.(*WaitGroup).Wait(0x14000012140)
    /usr/local/go/src/sync/waitgroup.go:136 +0x88
demo.Test_WaitGroup_Done(0x0?)
    ./done_test.go:43 0xd0
testing.tRunner(0x14000136340, 0x100fa1580)
    /usr/local/go/src/testing/testing.go:1439 +0x110
created by testing.(*T).Run
    /usr/local/go/src/testing/testing.go:1486 +0x300
exit status 2
FAIL    demo    1.225s

Go Version: go1.19

If you call sync.WaitGroup.Done more than the number of items you added with sync.WaitGroup.Add, the sync.WaitGroup.Done method panics, Listing 13.12. The result is the same as if you called sync.WaitGroup.Add with a negative number.

Listing 13.12 Panicking from Decrementing sync.WaitGroup Too Many Times
func Test_WaitGroup_Done(t *testing.T) {
    t.Parallel()

    func() {
        // defer a function to catch the panic
        defer func() {

            // recover the panic
            if r := recover(); r != nil {
                // mark the test as a failure
                t.Fatal(r)
            }
        }()

        // create a new waitgroup (count: 0)
        var wg sync.WaitGroup

        // call done creating a negative
        // waitgroup counter
        wg.Done()

        // this line is never reached
        fmt.Println("waitgroup is unblocked")
    }()

}

$ go test -v -timeout 1s

=== RUN   Test_WaitGroup_Done
=== PAUSE Test_WaitGroup_Done
=== CONT  Test_WaitGroup_Done
    done_test.go:20: sync: negative WaitGroup counter
--- FAIL: Test_WaitGroup_Done (0.00s)
FAIL
exit status 1
FAIL    demo    0.416s

Go Version: go1.19

Wrapping Up Wait Groups

Using a sync.WaitGroup is a great way to manage the number of goroutines or any other number of tests that need to finish before your program can continue.

As you can see, we can effectively use a sync.WaitGroup to manage the thumbnail generator goroutines from our initial example.

In Listing 13.13, we create a new sync.WaitGroup. Then, in the for loop, we use the sync.WaitGroup.Add method to add 1 to the sync.WaitGroup. We then pass a pointer to the generateThumbnail function to sync.WaitGroup. A pointer is needed because the generateThumbnail function needs to be able to modify the sync.WaitGroup by calling the sync.WaitGroup.Done method.

Finally, we call the sync.WaitGroup.Wait method to wait for all of the goroutines to finish.

Listing 13.13 Using a sync.WaitGroup to Manage the Thumbnail Generator Goroutines
func Test_ThumbnailGenerator(t *testing.T) {
    t.Parallel()

    // image that we need thumbnails for
    const image = "foo.png"

    var wg sync.WaitGroup

    // start 5 goroutines to generate thumbnails
    for i := 0; i < 5; i++ {
        wg.Add(1)

        // start a new goroutine for each thumbnail
        go generateThumbnail(&wg, image, i+1)
    }

    fmt.Println("Waiting for thumbnails to be generated")

    // wait for all goroutines to finish
    wg.Wait()

    fmt.Println("Finished generate all thumbnails")
}

The generateThumbnail function now receives a pointer to the sync.WaitGroup and defers a call to the sync.WaitGroup.Done method to indicate that the goroutine is finished when the function exits.

Finally, as you can see from our test output in Listing 13.14, the application now finishes successfully.

Listing 13.14 Generating Thumbnails Using a sync.WaitGroup
func generateThumbnail(wg *sync.WaitGroup, image string, size int) {
    defer wg.Done()

    // thumbnail to be generated
    thumb := fmt.Sprintf("%s@%dx.png", image, size)

    fmt.Println("Generating thumbnail:", thumb)

    // wait for the thumbnail to be ready
    time.Sleep(time.Millisecond * time.Duration(size))

    fmt.Println("Finished generating thumbnail:", thumb)
}

$ go test -v

=== RUN   Test_ThumbnailGenerator
=== PAUSE Test_ThumbnailGenerator
=== CONT  Test_ThumbnailGenerator
Waiting for thumbnails to be generated
Generating thumbnail: foo.png@5x.png
Generating thumbnail: foo.png@3x.png
Generating thumbnail: foo.png@4x.png
Generating thumbnail: foo.png@2x.png
Generating thumbnail: foo.png@1x.png
Finished generating thumbnail: foo.png@1x.png
Finished generating thumbnail: foo.png@2x.png
Finished generating thumbnail: foo.png@3x.png
Finished generating thumbnail: foo.png@4x.png
Finished generating thumbnail: foo.png@5x.png
Finished generate all thumbnails
--- PASS: Test_ThumbnailGenerator (0.01s)
PASS
ok      demo    0.310s

Go Version: go1.19

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020