Go 1.9 Multi-thread safe map function module

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. "Package Main//go 1.9 Multi-thread safe map function Module//qq:29295842 Welcome Technical Exchange Import (//" FMT "" Sync ") var (map_list sync). MAP//AD configuration information wgx sync. Waitgroup//) func Thread_map_add (ID string, Rows_map map[string]interface{}) {//Add data map_list. Store (ID, rows_map)}func thread_map_revise (ID string, Rows_map map[string]interface{}) {//modify WGX. ADD (1)//number of Threads go func () {map_list. Loadorstore (ID, ROWS_MAP)//Modify WGX. Done ()} () Wgx. Wait ()//waits for}func thread_map_delete (ID string) {//delete WGX. ADD (1)//number of Threads go func () {map_list. Delete (ID)//Remove WGX. Done ()} () Wgx. Wait ()//waits for}func thread_map_read (ID string) (bool, String, map[string]interface{}) {//Read read_bool: = Falsevalue: = Make (M ap[string]interface{}) value2, err: = Map_list. Load (ID)//key Read if Err {if valuexa, OK: = value2. ( map[string]interface{}); OK {value = Valuexaread_bool = True}}//fmt. Print ("===%v==%v==\n", data, err)//traversal read//map_list. Range (func (Key, value2 interface{}) bool {//Read data//fmt. Println (Key, "-----------", value2)////if valuexa, OK: = value2. (map[string]interface{}); OK {////read_bool = True//////key = Fmt. Sprintf ("%v", key)////value = Valuexa////}//return true//}) return Read_bool, ID, value}//fmt. Println ("----------------")//rows_map: = Make (map[string]interface{})//rows_map["db_name"] = "098765"//rows_map[" List "] =" 1234567 "//map_add (" abc ", ROWS_MAP)//rows_map = Make (map[string]interface{})//rows_map[" db_name "] =" aaaaaa " rows_map["List"] = "bbbbbbb"////map_add ("123", Rows_map)//map_revise ("abc", ROWS_MAP)//rows_map3: = Make (map[ string]interface{})//rows_map3["db_name"] = "rrrrr"//rows_map3["list" = "eeeeeee"//map_add ("1234", ROWS_MAP3)// Read_bool, key, Re_map: = Map_read ("abc")//fmt. Printf ("==%v==%v==%v==\n", Read_bool, Key, re_map["Db_name"]) "752 reads  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.