{"id":353,"date":"2015-02-24T07:29:10","date_gmt":"2015-02-24T07:29:10","guid":{"rendered":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=353"},"modified":"2017-12-04T07:47:25","modified_gmt":"2017-12-04T07:47:25","slug":"the-sharedvars-module","status":"publish","type":"page","link":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=353","title":{"rendered":"The sharedvars module"},"content":{"rendered":"<p>The <code>sharedvars<\/code> module is an extension module. \u00a0Its purpose is to provide new primitives to the <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=279\">Orchids language<\/a>.<\/p>\n<p>All variables are thread-local in Orchids: if you use you variable <code>$x<\/code> in a \u00a0rule, then only the current thread sees the values of <code>$x<\/code>. \u00a0The <code>sharedvars<\/code> module allows one to create the equivalent of global variables, shared by all threads and all rules.<\/p>\n<p>The name is slightly misleading:\u00a0<em>sharedvars<\/em> are not variables, they are just entries in a \u00a0global hash table. \u00a0One creates a\u00a0<em>sharedvar<\/em>\u00a0by using the <code>Set<\/code> configuration option, or by calling <code>set_shared_var<\/code>, e.g., <code>set_shared_var(\"my_database\", \"orchids.sql\")<\/code> or <code>set_shared_var(\"last_time_accessed\", $time)<\/code>, and other threads can obtain the value by reading <code>get_shared_var(\"my_database\")<\/code> or <code>get_shared_var(\"last_time_accessed\")<\/code> respectively.<\/p>\n<h3>Configuration options<\/h3>\n<p><code>&lt;module sharedvars&gt;<\/code><\/p>\n<ul>\n<li><code>HashSize<\/code> <em>n<\/em>: defines the size of the global hash size. \u00a0Default is 1021.<\/li>\n<li><code>Set<\/code> <em>name<\/em> <em>value<\/em>: initialize sharedvar\u00a0<em>name<\/em> to the string\u00a0<em>value<\/em> (between quotes).<\/li>\n<\/ul>\n<p><code>&lt;\/module&gt;<\/code><\/p>\n<h3>Primitives<\/h3>\n<ul>\n<li><strong><code>set_shared_var<\/code><\/strong> : <code>str<\/code>, <code>str<\/code> \u2192 <code>int<\/code><br \/>\nset a sharedvar to a value<\/p>\n<ul>\n<li>usage: <code>set_shared_var<\/code>(<em>var-name<\/em>, <em>value<\/em>)<br \/>\nsets the value of the sharedvar\u00a0<em>var-name<\/em> to <em>value<\/em>, creating it if necessary<\/li>\n<li>returns: 1 (true)<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>get_shared_var<\/code><\/strong> : <code>str<\/code> \u2192 <code>str<\/code><br \/>\nget a sharedvar&#8217;s \u00a0value<\/p>\n<ul>\n<li>usage: <code>get_shared_var<\/code>(<em>var-name<\/em>)<\/li>\n<li>returns: the value of the sharedvar\u00a0<em>var-name<\/em> if it exists, or the undefined null value otherwise<\/li>\n<\/ul>\n<\/li>\n<li><strong><code>del_shared_var<\/code><\/strong> : <code>str<\/code> \u2192 <code>int<\/code><br \/>\ndelete a sharedvar<\/p>\n<ul>\n<li>usage: <code>del_shared_var<\/code>(<em>var-name<\/em>)<\/li>\n<li>returns: 1 (true) if sharedvar\u00a0<em>var-name<\/em> was successfully deleted, 0 (false) if sharedvar\u00a0<em>var-name<\/em> did not exist<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The sharedvars module is an extension module. \u00a0Its purpose is to provide new primitives to the Orchids language. All variables are thread-local in Orchids: if you use you variable $x in a \u00a0rule, then only the current thread sees the values of $x. \u00a0The sharedvars module allows one to create the equivalent of global variables, &hellip; <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=353\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">The sharedvars module<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-353","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=353"}],"version-history":[{"count":3,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/353\/revisions"}],"predecessor-version":[{"id":716,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/353\/revisions\/716"}],"wp:attachment":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}